Mysql forces me to fill in fields not null suddenly [mysql mode strict]

3

PHP PDO or MYSQL is forcing me, from one day to the next, to save fields not null of a table, before, if it was an integer, mysql automatically put a 0 .

Let me explain.

I have this table: clients

id int auto incremental not null
nombre text not null
apellidos text not null
id_usuario int not null

And this is my query:

INSERT INTO clientes(nombre, apellidos) VALUES(:nombre, :apellidos)

This query 1 day ago, without changing the code, I worked fine, filled the fields nombre and apellidos , automatically filled the field id auto incrementándose and the field id_usuario put a 0 automatically mysql And it did not give any error.

Today, it does not work anymore, it gives me the following error:

PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000]: General error: 1364 Field 'id_usuario' doesn't have a default value.

It's also happening to me with the empty strings, before if I passed an empty string to a field int , it automatically interpreted it as nothing and set the value 0 . Now give the error:

PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ''

I think that Mysql has become restrictive from one day to the next, I do not know if it has been updated alone or that it has happened ... is there any way to change this so that it is as before?

EDIT: Viewing the log in Ubuntu, today at 6 am Mysql has been updated and passed from version 5.7.21 to 5.7.22. Surely it has something to do.

Greetings and thanks.

    
asked by Salpicaduras 25.04.2018 в 15:58
source

1 answer

1

Apparently with the MySQL update some attributes that made MYSQL more restrictive were activated.

This is modifiable in the MYSQL file my.cnf.

You can find out which parameters have the SQL_MODE of your MYSQL with the command:

SELECT @@sql_mode;

If you want to modify this you have to go to:

/etc/mysql/my.cnf

And add the statement below [mysqld]:

sql-mode=""

Inside the quotes you can set the parameters you want or leave it empty, according to your needs.

Then restart mysql and that's it.

sudo service mysql restart

Greetings and thanks for everything.

    
answered by 29.04.2018 / 21:14
source