Related
I'm replicating from mysql 5.6.33 to 5.7.41. I have a table with a datetime field. If I understand correctly, between 5.6 and 5.7 the decreased the space a datetime field uses because it doesn't store timezone data. (but a timestamp does).
This query works on 5.7 (note the presence of the timezone field):
select count(*) from login_activities where date_created < '2023-01-15 04:00:15 -0800';
This delete statement does not work:
delete from login_activities where date_created < '2023-01-15 04:00:15 -0800'
ERROR:
Error 'Incorrect datetime value: '2023-01-15 04:00:15 -0800' for column 'date_created' at row 1' on query. Default database: 'sms'. Query: 'delete from login_activities where date_created < '2023-01-15 04:00:15 -0800''
How can I get the delete to work in the same way the select works? I've even removed sql_mode entries but still can't get it to work in 5.7
edit:
not sure if this matters, but the error with the delete statement is happining during replication (5.6 -> 5.7), but I'm running the select statement manually. I haven't tried running the delete statement manually because it will through off the replication.
I'm running MySql Server 5.7.11 and this sentence:
updated datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
is not working. Giving the error:
ERROR 1067 (42000): Invalid default value for 'updated'
But the following:
updated datetime NOT NULL DEFAULT '1000-01-01 00:00:00'
just works.
The same case for DATE.
As a sidenote, it is mentioned in the MySQL docs:
The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.
even if they also say:
Invalid DATE, DATETIME, or TIMESTAMP values are converted to the “zero” value of the appropriate type ('0000-00-00' or '0000-00-00 00:00:00').
Having also into account the second quote from MySQL documentation, could anyone let me know why it is giving that error?
The error is because of the sql mode which can be strict mode as per latest MYSQL 5.7 documentation
MySQL Documentation 5.7 says:
Strict mode affects whether the server permits '0000-00-00' as a valid date:
If strict mode is not enabled, '0000-00-00' is permitted and inserts produce no warning.
If strict mode is enabled, '0000-00-00' is not permitted and inserts produce an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning.
To Check MYSQL mode
SELECT ##GLOBAL.sql_mode global, ##SESSION.sql_mode session
Disabling STRICT_TRANS_TABLES mode
However to allow the format 0000-00-00 00:00:00you have to disable STRICT_TRANS_TABLES mode in mysql config file or by command
By command
SET sql_mode = '';
or
SET GLOBAL sql_mode = '';
Using the keyword GLOBAL requires super previliges and it affects the operations all clients connect from that time on
if above is not working than go to /etc/mysql/my.cnf (as per ubuntu) and comment out STRICT_TRANS_TABLES
Also, if you want to permanently set the sql mode at server startup then include SET sql_mode='' in my.cnf on Linux or MacOS. For windows this has to be done in my.ini file.
Note
However strict mode is not enabled by default in MYSQL 5.6. Hence it does not produce the error as per MYSQL 6 documentation which says
MySQL permits you to store a “zero” value of '0000-00-00' as a “dummy date.” This is in some cases more convenient than using NULL values, and uses less data and index space. To disallow '0000-00-00', enable the NO_ZERO_DATE SQL mode.
UPDATE
Regarding the bug matter as said by #Dylan-Su:
I don't think this is the bug it the way MYSQL is evolved over the time due to which some things are changed based on further improvement of the product.
However I have another related bug report regarding the NOW() function
Datetime field does not accept default NOW()
Another Useful note [see Automatic Initialization and Updating for TIMESTAMP and DATETIME]
As of MySQL 5.6.5, TIMESTAMP and DATETIME columns can be automatically initializated and updated to the current date and time (that is, the current timestamp). Before 5.6.5, this is true only for TIMESTAMP, and for at most one TIMESTAMP column per table. The following notes first describe automatic initialization and updating for MySQL 5.6.5 and up, then the differences for versions preceding 5.6.5.
Update Regarding NO_ZERO_DATE
As of MySQL as of 5.7.4 this mode is deprecated. For previous version you must comment out the respective line in the config file. Refer MySQL 5.7 documentation on NO_ZERO_DATE
I had this error with WAMP 3.0.6 with MySql 5.7.14.
Solution:
change line 70 (if your ini file is untouched) in c:\wamp\bin\mysql\mysql5.7.14\my.ini file from
sql-mode= "STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER"
to
sql-mode="ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER"
and restart all services.
This will disable strict mode. As per the documentation, “strict mode” means a mode with either or both STRICT_TRANS_TABLES or STRICT_ALL_TABLES enabled.
The documentation says:
"The default SQL mode in MySQL 5.7 includes these modes:
ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE,
NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, and
NO_ENGINE_SUBSTITUTION."
I got into a situation where the data was mixed between NULL and 0000-00-00 for a date field. But I did not know how to update the '0000-00-00' to NULL, because
update my_table set my_date_field=NULL where my_date_field='0000-00-00'
is not allowed any more.
My workaround was quite simple:
update my_table set my_date_field=NULL where my_date_field<'0000-01-01'
because all the incorrect my_date_field values (whether correct dates or not) were from before this date.
First select current session sql_mode:
SELECT ##SESSION.sql_mode;
Then you will get something like that default value:
'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
and then set sql_mode without 'NO_ZERO_DATE':
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
If you have grants, you can do it also for GLOBAL:
SELECT ##GLOBAL.sql_mode;
SET GLOBAL sql_mode = '...';
Config syntax issue
On some versions of MYSQL (tested 5.7.*) under *nix systems you should use this syntax:
[mysqld]
sql-mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_ENGINE_SUBSTITUTION"
These won't work:
dash no quotes
sql-mode=NO_ENGINE_SUBSTITUTION
underscore no quotes
sql_mode=NO_ENGINE_SUBSTITUTION
underscore and quotes
sql_mode="NO_ENGINE_SUBSTITUTION"
A more complete review of config values and sql-mode:
How to setup permanent Sql Mode flags
Just add the line: sql_mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
inside file: /etc/mysql/mysql.conf.d/mysqld.cnf
then sudo service mysql restart
It works for 5.7.8:
mysql> create table t1(updated datetime NOT NULL DEFAULT '0000-00-00 00:00:00');
Query OK, 0 rows affected (0.01 sec)
mysql> show create table t1;
+-------+-------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-------+-------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc |
+-----------+
1 row in set (0.00 sec)
You can create a SQLFiddle to recreate your issue.
http://sqlfiddle.com/
If it works for MySQL 5.6 and 5.7.8, but fails on 5.7.11. Then it probably is a regression bug for 5.7.11.
To solve the problem with MySQL Workbench (After applying the solution on the server side) :
Remove SQL_MODE to TRADITIONAL in the preferences panel.
This answer it's just for MySQL 5.7:
Best is not really set in blank the sql_mode, instead use in PHP a session variable with:
SET SESSION sql_mode= 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
So at least you keep the other default values.
It's crazy that mysql documentation is not clear, you need delete to these default values in sql_mode:
NO_ZERO_IN_DATE,NO_ZERO_DATE, I understand, but in the future versions this will be discontinued.
STRICT_ALL_TABLES, with this, before parameters will be ignored, so you need to delete it too.
Finally TRADITIONAL too, but documentation speaks about this parameter: “give an error instead of a warning” when inserting an incorrect value into a column", with this parameter, dates with zero values is not inserted, but without yes.
MySQL is not really organised with these parameters and combinations.
Option combinations for mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64).
Doesn't throw:
STRICT_TRANS_TABLES + NO_ZERO_DATE
Throws:
STRICT_TRANS_TABLES + NO_ZERO_IN_DATE
My settings in /etc/mysql/my.cnf on Ubuntu:
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
set global sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
I've tested a fix as follow:
1). On the file "system/library/db/mysqli.php" search and comment the line:
"$this->connection->query("SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'");"
2) Add the following line above the one you just commented:
// Correction by Added by A.benkorich
$this->connection->query("SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY'");
Select the database and run SQL query:
SELECT ##GLOBAL.sql_mode global, ##SESSION.sql_mode session
1. Use following command to change the default date to current_timestamp:-
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT
NULL DEFAULT CURRENT_TIMESTAMP
2. Use following command to change the default date to NULL:-
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT
NULL DEFAULT NULL
3. Use following command to change default date for more than 1 column
using single SQL query:-
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT NULL
DEFAULT CURRENT_TIMESTAMP, CHANGE `post_date_gmt` `post_date_gmt`
DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `post_modified`
`post_modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE
`post_modified_gmt` `post_modified_gmt` DATETIME NOT NULL DEFAULT
CURRENT_TIMESTAMP;
In directory xampp/mysql/bin
Open "my.ini" and change line: sql_mode for ->
"sql_mode=NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE"
REMOVE "NO_ZERO_IN_DATE"
I was working on a new project, tried to add a new column
ALTER TABLE prefix_example_table ADD COLUMN stackoverflow decimal(11,3) NOT NULL
And got this error
#1292 - Incorrect date value: '0000-00-00'
For another column which i didn't even tried to add a new data to it, the Column that returned this error had the Default value '0000-00-00' for type Date .
As #geeksal mentioned
Strict mode affects whether the server permits '0000-00-00' as a valid date: If strict mode is not enabled, '0000-00-00' is permitted and inserts produce no warning. If strict mode is enabled, '0000-00-00' is not permitted and inserts produce an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning.
I have tried for hours thought the problem was related to PRIVILAGES
This saved my hours of work.
SET GLOBAL sql_mode = '';
I have two questions:
Why does mysql is not able to notify error when inserting wrong date 0000-00-00 when in the table definition its set to not null..?
example Schema: here
Now if change the duedate to 1970-01-01 it shows error
Incorrect date value 0000-00-00 for the column duedate at row1
update my_list set duedate = '1970-01-01' where duedate = '0000-00-00';
I tried to modify the column but it still shows the same error
ALTER TABLE `my_list` modify `duedate` date NULL;
ALTER TABLE `my_list` MODIFY `duedate` DATE NOT NULL DEFAULT '1970-01-01';
How do I change the duedate to 1970-01-01 for 0000-00-00;
I got the database from the client so unfortunately work on my.cnf file.
More info:
MYSQL version: 5.5
EDIT:
This is working
update my_list set duedate = '1970-01-01' where id = 16;
but not
update my_list set duedate = '1970-01-01' where duedate = '0000-00-00';
Cast duedate to string:
update my_list set duedate = '1970-01-01' where DATE_FORMAT(duedate, '%Y-%m-%d') = '0000-00-00';
You are not enable modify and update date value to '0000-00-00' as a dummy date. because of MySQL permits you to store a “zero” value. To disallow '0000-00-00', enable the NO_ZERO_DATE SQL mode.
Additionally strict mode has to be enabled for disallowing "zero" values:
Check version and SQL mode
SELECT version();
SELECT ##GLOBAL.sql_mode global, ##SESSION.sql_mode session
Disabling STRICT_TRANS_TABLES mode
you have to disable STRICT_TRANS_TABLES mode in mysql config file or by command
By command
SET sql_mode = '';
or
SET GLOBAL sql_mode = '';
if above is not working than go to /etc/mysql/my.cnf (as per ubuntu) and comment out STRICT_TRANS_TABLES
Also, if you want to permanently set the sql mode at server startup then include SET sql_mode='' in my.cnf on Linux. For windows this has to be done in my.ini file.
if above is not working than go to /etc/mysql/my.cnf (as per ubuntu) and comment out STRICT_TRANS_TABLES
Also, if you want to permanently set the sql mode at server startup then include SET sql_mode='' in my.cnf on Linux. For windows this has to be done in my.ini file.
Note
MySQL permits you to store a “zero” value of '0000-00-00' as a “dummy date.” This is in some cases more convenient than using NULL values, and uses less data and index space. To disallow '0000-00-00', enable the NO_ZERO_DATE SQL mode.
Update Regarding NO_ZERO_DATE
As of MySQL as of 5.7.4 this mode is deprecated.Refer MySQL 5.7 documentation on NO_ZERO_DATE
This works
update my_list
set duedate = '1970-01-01'
where to_days(duedate)IS NULL
at least in sqlfiddle
I'm running MySql Server 5.7.11 and this sentence:
updated datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
is not working. Giving the error:
ERROR 1067 (42000): Invalid default value for 'updated'
But the following:
updated datetime NOT NULL DEFAULT '1000-01-01 00:00:00'
just works.
The same case for DATE.
As a sidenote, it is mentioned in the MySQL docs:
The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.
even if they also say:
Invalid DATE, DATETIME, or TIMESTAMP values are converted to the “zero” value of the appropriate type ('0000-00-00' or '0000-00-00 00:00:00').
Having also into account the second quote from MySQL documentation, could anyone let me know why it is giving that error?
The error is because of the sql mode which can be strict mode as per latest MYSQL 5.7 documentation
MySQL Documentation 5.7 says:
Strict mode affects whether the server permits '0000-00-00' as a valid date:
If strict mode is not enabled, '0000-00-00' is permitted and inserts produce no warning.
If strict mode is enabled, '0000-00-00' is not permitted and inserts produce an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning.
To Check MYSQL mode
SELECT ##GLOBAL.sql_mode global, ##SESSION.sql_mode session
Disabling STRICT_TRANS_TABLES mode
However to allow the format 0000-00-00 00:00:00you have to disable STRICT_TRANS_TABLES mode in mysql config file or by command
By command
SET sql_mode = '';
or
SET GLOBAL sql_mode = '';
Using the keyword GLOBAL requires super previliges and it affects the operations all clients connect from that time on
if above is not working than go to /etc/mysql/my.cnf (as per ubuntu) and comment out STRICT_TRANS_TABLES
Also, if you want to permanently set the sql mode at server startup then include SET sql_mode='' in my.cnf on Linux or MacOS. For windows this has to be done in my.ini file.
Note
However strict mode is not enabled by default in MYSQL 5.6. Hence it does not produce the error as per MYSQL 6 documentation which says
MySQL permits you to store a “zero” value of '0000-00-00' as a “dummy date.” This is in some cases more convenient than using NULL values, and uses less data and index space. To disallow '0000-00-00', enable the NO_ZERO_DATE SQL mode.
UPDATE
Regarding the bug matter as said by #Dylan-Su:
I don't think this is the bug it the way MYSQL is evolved over the time due to which some things are changed based on further improvement of the product.
However I have another related bug report regarding the NOW() function
Datetime field does not accept default NOW()
Another Useful note [see Automatic Initialization and Updating for TIMESTAMP and DATETIME]
As of MySQL 5.6.5, TIMESTAMP and DATETIME columns can be automatically initializated and updated to the current date and time (that is, the current timestamp). Before 5.6.5, this is true only for TIMESTAMP, and for at most one TIMESTAMP column per table. The following notes first describe automatic initialization and updating for MySQL 5.6.5 and up, then the differences for versions preceding 5.6.5.
Update Regarding NO_ZERO_DATE
As of MySQL as of 5.7.4 this mode is deprecated. For previous version you must comment out the respective line in the config file. Refer MySQL 5.7 documentation on NO_ZERO_DATE
I had this error with WAMP 3.0.6 with MySql 5.7.14.
Solution:
change line 70 (if your ini file is untouched) in c:\wamp\bin\mysql\mysql5.7.14\my.ini file from
sql-mode= "STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER"
to
sql-mode="ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER"
and restart all services.
This will disable strict mode. As per the documentation, “strict mode” means a mode with either or both STRICT_TRANS_TABLES or STRICT_ALL_TABLES enabled.
The documentation says:
"The default SQL mode in MySQL 5.7 includes these modes:
ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE,
NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, and
NO_ENGINE_SUBSTITUTION."
I got into a situation where the data was mixed between NULL and 0000-00-00 for a date field. But I did not know how to update the '0000-00-00' to NULL, because
update my_table set my_date_field=NULL where my_date_field='0000-00-00'
is not allowed any more.
My workaround was quite simple:
update my_table set my_date_field=NULL where my_date_field<'0000-01-01'
because all the incorrect my_date_field values (whether correct dates or not) were from before this date.
First select current session sql_mode:
SELECT ##SESSION.sql_mode;
Then you will get something like that default value:
'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
and then set sql_mode without 'NO_ZERO_DATE':
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
If you have grants, you can do it also for GLOBAL:
SELECT ##GLOBAL.sql_mode;
SET GLOBAL sql_mode = '...';
Config syntax issue
On some versions of MYSQL (tested 5.7.*) under *nix systems you should use this syntax:
[mysqld]
sql-mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_ENGINE_SUBSTITUTION"
These won't work:
dash no quotes
sql-mode=NO_ENGINE_SUBSTITUTION
underscore no quotes
sql_mode=NO_ENGINE_SUBSTITUTION
underscore and quotes
sql_mode="NO_ENGINE_SUBSTITUTION"
A more complete review of config values and sql-mode:
How to setup permanent Sql Mode flags
Just add the line: sql_mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
inside file: /etc/mysql/mysql.conf.d/mysqld.cnf
then sudo service mysql restart
It works for 5.7.8:
mysql> create table t1(updated datetime NOT NULL DEFAULT '0000-00-00 00:00:00');
Query OK, 0 rows affected (0.01 sec)
mysql> show create table t1;
+-------+-------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-------+-------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc |
+-----------+
1 row in set (0.00 sec)
You can create a SQLFiddle to recreate your issue.
http://sqlfiddle.com/
If it works for MySQL 5.6 and 5.7.8, but fails on 5.7.11. Then it probably is a regression bug for 5.7.11.
To solve the problem with MySQL Workbench (After applying the solution on the server side) :
Remove SQL_MODE to TRADITIONAL in the preferences panel.
This answer it's just for MySQL 5.7:
Best is not really set in blank the sql_mode, instead use in PHP a session variable with:
SET SESSION sql_mode= 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
So at least you keep the other default values.
It's crazy that mysql documentation is not clear, you need delete to these default values in sql_mode:
NO_ZERO_IN_DATE,NO_ZERO_DATE, I understand, but in the future versions this will be discontinued.
STRICT_ALL_TABLES, with this, before parameters will be ignored, so you need to delete it too.
Finally TRADITIONAL too, but documentation speaks about this parameter: “give an error instead of a warning” when inserting an incorrect value into a column", with this parameter, dates with zero values is not inserted, but without yes.
MySQL is not really organised with these parameters and combinations.
Option combinations for mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64).
Doesn't throw:
STRICT_TRANS_TABLES + NO_ZERO_DATE
Throws:
STRICT_TRANS_TABLES + NO_ZERO_IN_DATE
My settings in /etc/mysql/my.cnf on Ubuntu:
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
set global sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
I've tested a fix as follow:
1). On the file "system/library/db/mysqli.php" search and comment the line:
"$this->connection->query("SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'");"
2) Add the following line above the one you just commented:
// Correction by Added by A.benkorich
$this->connection->query("SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY'");
Select the database and run SQL query:
SELECT ##GLOBAL.sql_mode global, ##SESSION.sql_mode session
1. Use following command to change the default date to current_timestamp:-
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT
NULL DEFAULT CURRENT_TIMESTAMP
2. Use following command to change the default date to NULL:-
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT
NULL DEFAULT NULL
3. Use following command to change default date for more than 1 column
using single SQL query:-
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT NULL
DEFAULT CURRENT_TIMESTAMP, CHANGE `post_date_gmt` `post_date_gmt`
DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `post_modified`
`post_modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE
`post_modified_gmt` `post_modified_gmt` DATETIME NOT NULL DEFAULT
CURRENT_TIMESTAMP;
In directory xampp/mysql/bin
Open "my.ini" and change line: sql_mode for ->
"sql_mode=NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE"
REMOVE "NO_ZERO_IN_DATE"
I was working on a new project, tried to add a new column
ALTER TABLE prefix_example_table ADD COLUMN stackoverflow decimal(11,3) NOT NULL
And got this error
#1292 - Incorrect date value: '0000-00-00'
For another column which i didn't even tried to add a new data to it, the Column that returned this error had the Default value '0000-00-00' for type Date .
As #geeksal mentioned
Strict mode affects whether the server permits '0000-00-00' as a valid date: If strict mode is not enabled, '0000-00-00' is permitted and inserts produce no warning. If strict mode is enabled, '0000-00-00' is not permitted and inserts produce an error, unless IGNORE is given as well. For INSERT IGNORE and UPDATE IGNORE, '0000-00-00' is permitted and inserts produce a warning.
I have tried for hours thought the problem was related to PRIVILAGES
This saved my hours of work.
SET GLOBAL sql_mode = '';
ok, i have people table and try run sql-script with the next command:
ALTER TABLE `people`
ADD COLUMN `name_spelling`
VARCHAR(255) NULL DEFAULT NULL
AFTER `last_name`;
Then I'll get a error:
[22001][1292] Data truncation: Incorrect date value:
'0000-00-00' for column 'birth_date' at row 35
At this row birth_date is NULL, but if I try set some date like 2016-05-05 at this column and row and than set NULL back -- all works is correct at this row, but get error on some next null date.
In addition, not all null date values return error.
Maybe your MySQL has some option such as the NO_ZERO_DATE SQL mode (I think it's not the only mysql config that prevents 0000-00-00 dates). This would prevent you from using 0000-00-00 as a value. It happened to me before that I had a table already created violating that condition. It will not be editable until you change the value or disable what's preventing you to set 0 dates.
For reference :http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html
I ran into this issue once and the fix i had was to to edit mysql.cnf file
Replace : sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
with this :
sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
Notice i removed the No_ZEROs in that options.