Php 为什么Laravel能够雄辩地生成没有引号的SQL?
我正在尝试在我的Laravel安装上运行Php 为什么Laravel能够雄辩地生成没有引号的SQL?,php,laravel,laravel-5,eloquent,Php,Laravel,Laravel 5,Eloquent,我正在尝试在我的Laravel安装上运行sudo php artisan migrate db:seed,出现以下错误: [Illuminate\Database\QueryException] Array to string conversion (SQL: insert in
sudo php artisan migrate db:seed
,出现以下错误:
[Illuminate\Database\QueryException]
Array to string conversion (SQL: insert into `sponsor_phones` (`phone_number`, `type`, `is_primary`, `sponsor_id`, `updated_at`, `created_at
`) values (247-216-6255 x4356, Home, 1, 101, 2017-05-30 23:31:59, 2017-05-30 23:31:59))
似乎Eloquent创建的SQL在需要的地方缺少引号。在正确的位置(下面)添加报价允许它运行
[Illuminate\Database\QueryException]
Array to string conversion (SQL: insert into `sponsor_phones` (`phone_number`, `type`, `is_primary`, `sponsor_id`, `updated_at`, `created_at
`) values (247-216-6255 x4356, Home, 1, 101, 2017-05-30 23:31:59, 2017-05-30 23:31:59))
insert into
`sponsor_phones`
(`phone_number`,
`type`,
`is_primary`,
`sponsor_id`,
`updated_at`,
`created_at`
)
values
(
'(732) 540-9730',
'Busi',
0,
51,
'2017-05-27 21:53:44',
'2017-05-27 21:53:44');
我不确定是什么原因导致了这个错误,寻找雄辩不加引语的原因似乎无法产生任何有用的结果
[Illuminate\Database\QueryException]
Array to string conversion (SQL: insert into `sponsor_phones` (`phone_number`, `type`, `is_primary`, `sponsor_id`, `updated_at`, `created_at
`) values (247-216-6255 x4356, Home, 1, 101, 2017-05-30 23:31:59, 2017-05-30 23:31:59))
我已经准备好了一个备份,以便您可以查看一下(因为作为一个开源项目,它无论如何都需要一个备份)。问题不在于报价。在ModelFactory.php中,在函数
getTypePhone
、getTypeEmail
和getTypeAddress
中返回
[Illuminate\Database\QueryException]
Array to string conversion (SQL: insert into `sponsor_phones` (`phone_number`, `type`, `is_primary`, `sponsor_id`, `updated_at`, `created_at
`) values (247-216-6255 x4356, Home, 1, 101, 2017-05-30 23:31:59, 2017-05-30 23:31:59))
return $faker->randomElements(array('Work', 'Cell', 'Home', "VoIP"));
$faker->randomElements
返回一个数组。相反,使用$faker->randomElement
从数组中返回单个元素
[Illuminate\Database\QueryException]
Array to string conversion (SQL: insert into `sponsor_phones` (`phone_number`, `type`, `is_primary`, `sponsor_id`, `updated_at`, `created_at
`) values (247-216-6255 x4356, Home, 1, 101, 2017-05-30 23:31:59, 2017-05-30 23:31:59))
return $faker->randomElement(array('Work', 'Cell', 'Home', "VoIP"));
非常感谢。很容易错过那里。有时候,你只需要第二双眼睛。仍然需要在模型工厂中找出一些其他的东西,但这个错误至少会得到处理。