ConsoleTVs's avatar

Mysql strict mode changed [SOLVED]

hello, I used to insert data in the database that sometimes was not full, for example;

$user = new App\User;
$user->email = '[email protected]';
$user->password = \Crypt::encrypt('test');
$user->save();

This now fails so badly giving me a non-sense SQL (the SQL is trying to insert data i did not even want to and of course it's not set)

SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (SQL: insert into `users` (`email`, `password`, `updated_at`, `created_at`) values ([email protected], eyJpdiI6Ikc0eHV3bzBPZFZFQVdYd2Jwd1dDSXc9PSIsInZhbHVlIjoiZzVPbkVzazhFRE9xbnZCSnZEdkI0dz09IiwibWFjIjoiZjQ0MTUyNzY4ZWVkOGUxYWNmYmJiM2UzMmQ3N2YzMjEzZGExZjNlMjdiMzJlNDliYzU3OWNmNTE3ODgwMmZjMiJ9, 2016-08-27 00:47:06, 2016-08-27 00:47:06))

Any solutions?

0 likes
2 replies
ConsoleTVs's avatar
ConsoleTVs
OP
Best Answer
Level 2

SOLUTION:

Seems like MySQL mode was set to strict, from the laravel fresh installation

To solve it; go to config/database.php

'mysql' => [
        //...
        'strict' => false,
        ],
2 likes
sergiq's avatar

Although this question was response you should not disabled strict mode. The correct way would be change the field and allow it to be null.

Data structure should be as robust as your code so you should not be able to put "what i want" in a specific field (typology and format)

1 like

Please or to participate in this conversation.