Error in mysql when setting default value for DATE or DATETIME










75















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?










share|improve this question

















  • 7





    Why would you want a default that is obviously meaningless? If the date is unknown then that's exactly what NULL is for.

    – Tom H
    Apr 2 '16 at 14:25











  • As a note: This works in version 5.6 on SQL Fiddle -- sqlfiddle.com/#!9/02c98.

    – Gordon Linoff
    Apr 2 '16 at 14:35











  • @Karlos check the updated answer.

    – geeksal
    Apr 2 '16 at 14:58















75















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?










share|improve this question

















  • 7





    Why would you want a default that is obviously meaningless? If the date is unknown then that's exactly what NULL is for.

    – Tom H
    Apr 2 '16 at 14:25











  • As a note: This works in version 5.6 on SQL Fiddle -- sqlfiddle.com/#!9/02c98.

    – Gordon Linoff
    Apr 2 '16 at 14:35











  • @Karlos check the updated answer.

    – geeksal
    Apr 2 '16 at 14:58













75












75








75


36






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?










share|improve this question














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?







mysql sql date datetime console






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 2 '16 at 14:11









EvhzEvhz

3,56142343




3,56142343







  • 7





    Why would you want a default that is obviously meaningless? If the date is unknown then that's exactly what NULL is for.

    – Tom H
    Apr 2 '16 at 14:25











  • As a note: This works in version 5.6 on SQL Fiddle -- sqlfiddle.com/#!9/02c98.

    – Gordon Linoff
    Apr 2 '16 at 14:35











  • @Karlos check the updated answer.

    – geeksal
    Apr 2 '16 at 14:58












  • 7





    Why would you want a default that is obviously meaningless? If the date is unknown then that's exactly what NULL is for.

    – Tom H
    Apr 2 '16 at 14:25











  • As a note: This works in version 5.6 on SQL Fiddle -- sqlfiddle.com/#!9/02c98.

    – Gordon Linoff
    Apr 2 '16 at 14:35











  • @Karlos check the updated answer.

    – geeksal
    Apr 2 '16 at 14:58







7




7





Why would you want a default that is obviously meaningless? If the date is unknown then that's exactly what NULL is for.

– Tom H
Apr 2 '16 at 14:25





Why would you want a default that is obviously meaningless? If the date is unknown then that's exactly what NULL is for.

– Tom H
Apr 2 '16 at 14:25













As a note: This works in version 5.6 on SQL Fiddle -- sqlfiddle.com/#!9/02c98.

– Gordon Linoff
Apr 2 '16 at 14:35





As a note: This works in version 5.6 on SQL Fiddle -- sqlfiddle.com/#!9/02c98.

– Gordon Linoff
Apr 2 '16 at 14:35













@Karlos check the updated answer.

– geeksal
Apr 2 '16 at 14:58





@Karlos check the updated answer.

– geeksal
Apr 2 '16 at 14:58












10 Answers
10






active

oldest

votes


















138














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






share|improve this answer




















  • 2





    UPDATE IGNORE is what I was looking for 👍🏻

    – Afanasii Kurakin
    Mar 26 '17 at 14:06






  • 1





    SET sql_mode = ''; works

    – Mike
    Apr 27 '17 at 9:04







  • 2





    Wrong. I have STRICT_TRANS_TABLES for my both MySQL instances, local and server. However, I can easily insert 0000-00-00 in my local instance, but cannot in my server instance - error is thrown. Why? Because my server MySQL config has NO_ZERO_DATE enabled. And my local doesn't have it.

    – Green
    Jul 21 '17 at 2:11












  • ok @Green I will figure out and update the answer if applicable

    – geeksal
    Jul 22 '17 at 12:06











  • In my case 'SET sql_mode = ""' did not work. 'SET GLOBAL sql_mode = "";' did the job for me.

    – arjen Stens
    Aug 23 '17 at 7:35


















14














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:wampbinmysqlmysql5.7.14my.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."







share|improve this answer
































    4














    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






    share|improve this answer
































      4














      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






      share|improve this answer




















      • 1





        Works for 5.7.23.

        – user2513149
        Aug 25 '18 at 20:33


















      2














      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 be a regression bug for 5.7.11.






      share|improve this answer






























        2














        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 = '...';





        share|improve this answer






























          1














          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 another default values.



          It's crazy that mysql documentation is not clear, you need delete this defeault values in sql_mode:



          NO_ZERO_IN_DATE,NO_ZERO_DATE, I understand, but in the future versiones this will be discontinued.



          STRICT_ALL_TABLES, with this, before parameters will be ignored, so you need delete it too.



          Finally TRADITIONAL too, but documentation speak 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.






          share|improve this answer
































            1














            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<'1000-01-01'


            because all the incorrect my_date_field values (whether correct dates or not) were from before this date.






            share|improve this answer




















            • 1





              Perfect quick solution. You could in fact also use <'0000-01-01' since it is of course a valid date.

              – Ricky McMaster
              Dec 28 '18 at 15:06


















            0














            To solve the problem with MySQL Workbench (After applying the solution on the server side) :



            Remove SQL_MODE to TRADITIONAL in the preferences panel.



            enter image description here






            share|improve this answer






























              0














              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"





              share|improve this answer






















                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36374335%2ferror-in-mysql-when-setting-default-value-for-date-or-datetime%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                10 Answers
                10






                active

                oldest

                votes








                10 Answers
                10






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                138














                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






                share|improve this answer




















                • 2





                  UPDATE IGNORE is what I was looking for 👍🏻

                  – Afanasii Kurakin
                  Mar 26 '17 at 14:06






                • 1





                  SET sql_mode = ''; works

                  – Mike
                  Apr 27 '17 at 9:04







                • 2





                  Wrong. I have STRICT_TRANS_TABLES for my both MySQL instances, local and server. However, I can easily insert 0000-00-00 in my local instance, but cannot in my server instance - error is thrown. Why? Because my server MySQL config has NO_ZERO_DATE enabled. And my local doesn't have it.

                  – Green
                  Jul 21 '17 at 2:11












                • ok @Green I will figure out and update the answer if applicable

                  – geeksal
                  Jul 22 '17 at 12:06











                • In my case 'SET sql_mode = ""' did not work. 'SET GLOBAL sql_mode = "";' did the job for me.

                  – arjen Stens
                  Aug 23 '17 at 7:35















                138














                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






                share|improve this answer




















                • 2





                  UPDATE IGNORE is what I was looking for 👍🏻

                  – Afanasii Kurakin
                  Mar 26 '17 at 14:06






                • 1





                  SET sql_mode = ''; works

                  – Mike
                  Apr 27 '17 at 9:04







                • 2





                  Wrong. I have STRICT_TRANS_TABLES for my both MySQL instances, local and server. However, I can easily insert 0000-00-00 in my local instance, but cannot in my server instance - error is thrown. Why? Because my server MySQL config has NO_ZERO_DATE enabled. And my local doesn't have it.

                  – Green
                  Jul 21 '17 at 2:11












                • ok @Green I will figure out and update the answer if applicable

                  – geeksal
                  Jul 22 '17 at 12:06











                • In my case 'SET sql_mode = ""' did not work. 'SET GLOBAL sql_mode = "";' did the job for me.

                  – arjen Stens
                  Aug 23 '17 at 7:35













                138












                138








                138







                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






                share|improve this answer















                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







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 19 '17 at 7:17

























                answered Apr 2 '16 at 14:46









                geeksalgeeksal

                2,79921534




                2,79921534







                • 2





                  UPDATE IGNORE is what I was looking for 👍🏻

                  – Afanasii Kurakin
                  Mar 26 '17 at 14:06






                • 1





                  SET sql_mode = ''; works

                  – Mike
                  Apr 27 '17 at 9:04







                • 2





                  Wrong. I have STRICT_TRANS_TABLES for my both MySQL instances, local and server. However, I can easily insert 0000-00-00 in my local instance, but cannot in my server instance - error is thrown. Why? Because my server MySQL config has NO_ZERO_DATE enabled. And my local doesn't have it.

                  – Green
                  Jul 21 '17 at 2:11












                • ok @Green I will figure out and update the answer if applicable

                  – geeksal
                  Jul 22 '17 at 12:06











                • In my case 'SET sql_mode = ""' did not work. 'SET GLOBAL sql_mode = "";' did the job for me.

                  – arjen Stens
                  Aug 23 '17 at 7:35












                • 2





                  UPDATE IGNORE is what I was looking for 👍🏻

                  – Afanasii Kurakin
                  Mar 26 '17 at 14:06






                • 1





                  SET sql_mode = ''; works

                  – Mike
                  Apr 27 '17 at 9:04







                • 2





                  Wrong. I have STRICT_TRANS_TABLES for my both MySQL instances, local and server. However, I can easily insert 0000-00-00 in my local instance, but cannot in my server instance - error is thrown. Why? Because my server MySQL config has NO_ZERO_DATE enabled. And my local doesn't have it.

                  – Green
                  Jul 21 '17 at 2:11












                • ok @Green I will figure out and update the answer if applicable

                  – geeksal
                  Jul 22 '17 at 12:06











                • In my case 'SET sql_mode = ""' did not work. 'SET GLOBAL sql_mode = "";' did the job for me.

                  – arjen Stens
                  Aug 23 '17 at 7:35







                2




                2





                UPDATE IGNORE is what I was looking for 👍🏻

                – Afanasii Kurakin
                Mar 26 '17 at 14:06





                UPDATE IGNORE is what I was looking for 👍🏻

                – Afanasii Kurakin
                Mar 26 '17 at 14:06




                1




                1





                SET sql_mode = ''; works

                – Mike
                Apr 27 '17 at 9:04






                SET sql_mode = ''; works

                – Mike
                Apr 27 '17 at 9:04





                2




                2





                Wrong. I have STRICT_TRANS_TABLES for my both MySQL instances, local and server. However, I can easily insert 0000-00-00 in my local instance, but cannot in my server instance - error is thrown. Why? Because my server MySQL config has NO_ZERO_DATE enabled. And my local doesn't have it.

                – Green
                Jul 21 '17 at 2:11






                Wrong. I have STRICT_TRANS_TABLES for my both MySQL instances, local and server. However, I can easily insert 0000-00-00 in my local instance, but cannot in my server instance - error is thrown. Why? Because my server MySQL config has NO_ZERO_DATE enabled. And my local doesn't have it.

                – Green
                Jul 21 '17 at 2:11














                ok @Green I will figure out and update the answer if applicable

                – geeksal
                Jul 22 '17 at 12:06





                ok @Green I will figure out and update the answer if applicable

                – geeksal
                Jul 22 '17 at 12:06













                In my case 'SET sql_mode = ""' did not work. 'SET GLOBAL sql_mode = "";' did the job for me.

                – arjen Stens
                Aug 23 '17 at 7:35





                In my case 'SET sql_mode = ""' did not work. 'SET GLOBAL sql_mode = "";' did the job for me.

                – arjen Stens
                Aug 23 '17 at 7:35













                14














                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:wampbinmysqlmysql5.7.14my.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."







                share|improve this answer





























                  14














                  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:wampbinmysqlmysql5.7.14my.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."







                  share|improve this answer



























                    14












                    14








                    14







                    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:wampbinmysqlmysql5.7.14my.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."







                    share|improve this answer















                    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:wampbinmysqlmysql5.7.14my.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."








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 12 '17 at 11:46









                    Aserre

                    3,32432043




                    3,32432043










                    answered Oct 16 '16 at 20:22









                    bg17awbg17aw

                    1,6021321




                    1,6021321





















                        4














                        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






                        share|improve this answer





























                          4














                          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






                          share|improve this answer



























                            4












                            4








                            4







                            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






                            share|improve this answer















                            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







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited May 23 '17 at 12:10









                            Community

                            11




                            11










                            answered Mar 9 '17 at 22:17









                            HeroselohimHeroselohim

                            6831714




                            6831714





















                                4














                                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






                                share|improve this answer




















                                • 1





                                  Works for 5.7.23.

                                  – user2513149
                                  Aug 25 '18 at 20:33















                                4














                                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






                                share|improve this answer




















                                • 1





                                  Works for 5.7.23.

                                  – user2513149
                                  Aug 25 '18 at 20:33













                                4












                                4








                                4







                                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






                                share|improve this answer















                                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







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Dec 24 '17 at 11:05









                                Thomas Smyth

                                3,99951831




                                3,99951831










                                answered Dec 24 '17 at 10:47









                                ferreidon aftahiferreidon aftahi

                                392




                                392







                                • 1





                                  Works for 5.7.23.

                                  – user2513149
                                  Aug 25 '18 at 20:33












                                • 1





                                  Works for 5.7.23.

                                  – user2513149
                                  Aug 25 '18 at 20:33







                                1




                                1





                                Works for 5.7.23.

                                – user2513149
                                Aug 25 '18 at 20:33





                                Works for 5.7.23.

                                – user2513149
                                Aug 25 '18 at 20:33











                                2














                                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 be a regression bug for 5.7.11.






                                share|improve this answer



























                                  2














                                  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 be a regression bug for 5.7.11.






                                  share|improve this answer

























                                    2












                                    2








                                    2







                                    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 be a regression bug for 5.7.11.






                                    share|improve this answer













                                    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 be a regression bug for 5.7.11.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Apr 2 '16 at 14:38









                                    Dylan SuDylan Su

                                    5,0041821




                                    5,0041821





















                                        2














                                        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 = '...';





                                        share|improve this answer



























                                          2














                                          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 = '...';





                                          share|improve this answer

























                                            2












                                            2








                                            2







                                            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 = '...';





                                            share|improve this answer













                                            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 = '...';






                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Nov 7 '17 at 14:38









                                            simhumilecosimhumileco

                                            7,01435152




                                            7,01435152





















                                                1














                                                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 another default values.



                                                It's crazy that mysql documentation is not clear, you need delete this defeault values in sql_mode:



                                                NO_ZERO_IN_DATE,NO_ZERO_DATE, I understand, but in the future versiones this will be discontinued.



                                                STRICT_ALL_TABLES, with this, before parameters will be ignored, so you need delete it too.



                                                Finally TRADITIONAL too, but documentation speak 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.






                                                share|improve this answer





























                                                  1














                                                  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 another default values.



                                                  It's crazy that mysql documentation is not clear, you need delete this defeault values in sql_mode:



                                                  NO_ZERO_IN_DATE,NO_ZERO_DATE, I understand, but in the future versiones this will be discontinued.



                                                  STRICT_ALL_TABLES, with this, before parameters will be ignored, so you need delete it too.



                                                  Finally TRADITIONAL too, but documentation speak 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.






                                                  share|improve this answer



























                                                    1












                                                    1








                                                    1







                                                    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 another default values.



                                                    It's crazy that mysql documentation is not clear, you need delete this defeault values in sql_mode:



                                                    NO_ZERO_IN_DATE,NO_ZERO_DATE, I understand, but in the future versiones this will be discontinued.



                                                    STRICT_ALL_TABLES, with this, before parameters will be ignored, so you need delete it too.



                                                    Finally TRADITIONAL too, but documentation speak 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.






                                                    share|improve this answer















                                                    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 another default values.



                                                    It's crazy that mysql documentation is not clear, you need delete this defeault values in sql_mode:



                                                    NO_ZERO_IN_DATE,NO_ZERO_DATE, I understand, but in the future versiones this will be discontinued.



                                                    STRICT_ALL_TABLES, with this, before parameters will be ignored, so you need delete it too.



                                                    Finally TRADITIONAL too, but documentation speak 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.







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Oct 20 '18 at 8:26









                                                    simhumileco

                                                    7,01435152




                                                    7,01435152










                                                    answered Jun 10 '17 at 12:35









                                                    stackdavestackdave

                                                    2,18552340




                                                    2,18552340





















                                                        1














                                                        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<'1000-01-01'


                                                        because all the incorrect my_date_field values (whether correct dates or not) were from before this date.






                                                        share|improve this answer




















                                                        • 1





                                                          Perfect quick solution. You could in fact also use <'0000-01-01' since it is of course a valid date.

                                                          – Ricky McMaster
                                                          Dec 28 '18 at 15:06















                                                        1














                                                        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<'1000-01-01'


                                                        because all the incorrect my_date_field values (whether correct dates or not) were from before this date.






                                                        share|improve this answer




















                                                        • 1





                                                          Perfect quick solution. You could in fact also use <'0000-01-01' since it is of course a valid date.

                                                          – Ricky McMaster
                                                          Dec 28 '18 at 15:06













                                                        1












                                                        1








                                                        1







                                                        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<'1000-01-01'


                                                        because all the incorrect my_date_field values (whether correct dates or not) were from before this date.






                                                        share|improve this answer















                                                        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<'1000-01-01'


                                                        because all the incorrect my_date_field values (whether correct dates or not) were from before this date.







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Dec 28 '18 at 15:54









                                                        Ricky McMaster

                                                        1,2971214




                                                        1,2971214










                                                        answered Oct 22 '18 at 13:54









                                                        Martin T.Martin T.

                                                        837




                                                        837







                                                        • 1





                                                          Perfect quick solution. You could in fact also use <'0000-01-01' since it is of course a valid date.

                                                          – Ricky McMaster
                                                          Dec 28 '18 at 15:06












                                                        • 1





                                                          Perfect quick solution. You could in fact also use <'0000-01-01' since it is of course a valid date.

                                                          – Ricky McMaster
                                                          Dec 28 '18 at 15:06







                                                        1




                                                        1





                                                        Perfect quick solution. You could in fact also use <'0000-01-01' since it is of course a valid date.

                                                        – Ricky McMaster
                                                        Dec 28 '18 at 15:06





                                                        Perfect quick solution. You could in fact also use <'0000-01-01' since it is of course a valid date.

                                                        – Ricky McMaster
                                                        Dec 28 '18 at 15:06











                                                        0














                                                        To solve the problem with MySQL Workbench (After applying the solution on the server side) :



                                                        Remove SQL_MODE to TRADITIONAL in the preferences panel.



                                                        enter image description here






                                                        share|improve this answer



























                                                          0














                                                          To solve the problem with MySQL Workbench (After applying the solution on the server side) :



                                                          Remove SQL_MODE to TRADITIONAL in the preferences panel.



                                                          enter image description here






                                                          share|improve this answer

























                                                            0












                                                            0








                                                            0







                                                            To solve the problem with MySQL Workbench (After applying the solution on the server side) :



                                                            Remove SQL_MODE to TRADITIONAL in the preferences panel.



                                                            enter image description here






                                                            share|improve this answer













                                                            To solve the problem with MySQL Workbench (After applying the solution on the server side) :



                                                            Remove SQL_MODE to TRADITIONAL in the preferences panel.



                                                            enter image description here







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Feb 9 '17 at 12:12









                                                            VindicVindic

                                                            1245




                                                            1245





















                                                                0














                                                                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"





                                                                share|improve this answer



























                                                                  0














                                                                  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"





                                                                  share|improve this answer

























                                                                    0












                                                                    0








                                                                    0







                                                                    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"





                                                                    share|improve this answer













                                                                    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"






                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Jul 21 '17 at 2:59









                                                                    GreenGreen

                                                                    7,71930103174




                                                                    7,71930103174



























                                                                        draft saved

                                                                        draft discarded
















































                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid


                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.

                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function ()
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36374335%2ferror-in-mysql-when-setting-default-value-for-date-or-datetime%23new-answer', 'question_page');

                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        這個網誌中的熱門文章

                                                                        How to read a connectionString WITH PROVIDER in .NET Core?

                                                                        Node.js Script on GitHub Pages or Amazon S3

                                                                        Museum of Modern and Contemporary Art of Trento and Rovereto