我在使用Laravel 5.1的模型工厂突然播种我的数据库时出现问题。我有这个很好,现在它不再工作了。
我尝试使用Carbon日期格式但仍然收到错误?
这是错误:
vagrant@homestead:~/Code/jobboard$ php artisan migrate:refresh --seed
Rolled back: 2015_06_10_162857_create_jobs_table
Rolled back: 2015_06_10_162653_create_users_table
Rolled back: 2015_06_10_153026_create_job_types_table
Rolled back: 2015_06_10_152237_create_job_categories_table
Rolled back: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2015_06_10_152237_create_job_categories_table
Migrated: 2015_06_10_153026_create_job_types_table
Migrated: 2015_06_10_162653_create_users_table
Migrated: 2015_06_10_162857_create_jobs_table
Seeded: UsersTableSeeder
[InvalidArgumentException]
A four digit year could not be found
Data missing
这是我设立的工厂:
$factory->define('App\Job', function ($faker) {
return [
'cat_name' => $faker->word,
'title' => $faker->sentence,
'location' => $faker->city,
'remote' => $faker->boolean($chanceOfGettingTrue = 50),
'type_name' => $faker->word,
'description' => $faker->paragraph,
'how_to_apply' => $faker->paragraph,
'company_name' => $faker->word,
'website' => $faker->url,
'logo' => $faker->imageUrl($width = 50, $height = 50),
'featured' => $faker->boolean($chanceOfGettingTrue = 50),
'expires_at' => $faker->dateTime($max = 'now')->format('Y-m-d h:i:s'),
'agree_terms' => $faker->boolean($chanceOfGettingTrue = 90),
'user_id' => $faker->numberBetween($min = 1, $max = 10),
'cat_id' => $faker->numberBetween($min = 1, $max = 9),
'type_id' => $faker->numberBetween($min = 1, $max = 5),
];
});
这是我的模特:
class Job extends Model
{
protected $table = 'jobs';
protected $primaryKey = 'job_id';
protected $fillable = [
'job_id',
'cat_name',
'title',
'location',
'remote',
'type_name',
'description',
'how_to_apply',
'company_name',
'website',
'logo',
'featured',
'expires_at',
'agree_terms',
'user_id',
'cat_id',
'type_id',
];
}
答案 0 :(得分:4)
不确定是否有其他人会发现这有用,但想要将解决方案发布到我自己的问题上,以防有人犯同样的错误。
问题是这一行:
factory( \App\Task::class, 10 )->create( [ 'user_id', $user->id ] );
如果你注意到,我应该有一个逗号,
,它应该是一个赋值运算符=>
。
应该是:
factory( \App\Task::class, 10 )->create( [ 'user_id' => $user->id ] );