Reputation: 99
In my UserFactory.php I have
$factory->define(App\Gear::class, function (Faker $faker) {
return [
'barcode' => $faker->isbn13,
]; });
I just want to execute in a 'barcode' column. But when I run php aritsan tinker
I get an error message: General error: 1364 Field 'name' doesn't have a default value
. But in database field 'name' i had value in column 'name'. What should I do to be able to randomly number the barcode in the barcode
column
Thanks
Upvotes: 0
Views: 66
Reputation: 6976
A factory is used for generating new models, usually for testing purposes. You are getting this error because you are attempting to create a user with only a barcode property.
If you want to use a factory to generate users and persist them to the database then you will need to provide all of the required fields.
$factory->define(App\Gear::class, function (Faker $faker) {
return [
'name' => $faker->name,
// plus any additional required fields
'barcode' => $faker->isbn13,
];
});
If you want to update existing users with a property you will need to create a database migration.
Upvotes: 1