Reputation: 27
I call the command:
php artisan db:seed
in Laravel 5.4. The console print me this error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1364 Field 'email' doesn't have a default v alue (SQL: insert intousers
(name
,password
,updated_at
,created_ at
) values (user, $2y$10$YAPLstS9Q/Z7vdL82oefieAo4ZToe4xAiNkLF4nygnniKDhWB njwO, 2017-08-02 16:00:42, 2017-08-02 16:00:42))[PDOException]
SQLSTATE[HY000]: General error: 1364 Field 'email' doesn't have a default value
I try set in database.php
file:
'strict' => false
, but this isn`t working. Ho fix this problem?
Upvotes: 1
Views: 1093
Reputation: 6276
Do following steps:
In your command line do: php artisan make:seeder UsersTableSeeder
. You can see the same file being created in database\seeds
folder now go to the file UsersTableSeeder.php
you will see run()
method, write the codes as below:
public function run()
{
DB::table('users')->insert([
'name' => str_random(10),
'email' => str_random(10).'@gmail.com',
'password' => bcrypt('secret'),
]);
}
Now after this you can use: php artisan db:seed
to seed the database or you can do: php artisan db:seed --class=UsersTableSeeder
to seed only your UsersTableSeeder
And final step go to file DatabaseSeeder.php
in database/seed
and in run()
function type this:
public function run()
{
$this->call(UsersTableSeeder::class);
}
Or you don't need to create UsersTableSeeder
you can simply copy
DB::table('users')->insert([
'name' => str_random(10),
'email' => str_random(10).'@gmail.com',
'password' => bcrypt('secret'),
]);
into run()
function in DatabaseSeeder.php
file
Hope this helps.
Upvotes: 0