mysql - Need to allow '0000-00-00 00:00:00' dates












2















I want zero dates to be allowed in MySQL. I have changed the sql_mode to ALLOW_INVALID_DATES,NO_ENGINE_SUBSTITUTION.



I have changed it in /etc/mysql/my.cnf.



Yet, I when I try to insert data I get the error,




Data truncation: Incorrect datetime value: '0000-00-00 00:00:00'




The MySQL version is 5.7.18.



Any ideas on this would be of great help.










share|improve this question




















  • 2





    What data were you inserting when this error happened? Why do you need to allow invalid dates?

    – Tim Biegeleisen
    Apr 24 '17 at 13:13






  • 1





    Did you restart the server?

    – Igor
    Apr 24 '17 at 13:14











  • Well, I think in varchar field. So, why you don't use varchar? when you execute select, update, delete, ... you can convert with DATE() like SELECT id FROM my_table where DATE(my_date_1) > DATE(my_date_2) ORDER BY DATE(my_date_3) DESC... And... you can check if is a zero date like WHERE my_date_1 = '0000-00-00 00:00:00'

    – Olaf Erlandsen
    Apr 24 '17 at 13:16













  • I get the data from SQL server and I pass it to mysql. The incoming date looks this way : '0000-00-00 00:00:00'. This is just a back up system, and I need to keep the data as it is in the source system

    – Rathi Rao
    Apr 24 '17 at 13:16











  • I cannot store the date in varchar as I cannot change the data type and I am not allowed to do it. And yeah, I did restart mysql after the changes

    – Rathi Rao
    Apr 24 '17 at 13:20
















2















I want zero dates to be allowed in MySQL. I have changed the sql_mode to ALLOW_INVALID_DATES,NO_ENGINE_SUBSTITUTION.



I have changed it in /etc/mysql/my.cnf.



Yet, I when I try to insert data I get the error,




Data truncation: Incorrect datetime value: '0000-00-00 00:00:00'




The MySQL version is 5.7.18.



Any ideas on this would be of great help.










share|improve this question




















  • 2





    What data were you inserting when this error happened? Why do you need to allow invalid dates?

    – Tim Biegeleisen
    Apr 24 '17 at 13:13






  • 1





    Did you restart the server?

    – Igor
    Apr 24 '17 at 13:14











  • Well, I think in varchar field. So, why you don't use varchar? when you execute select, update, delete, ... you can convert with DATE() like SELECT id FROM my_table where DATE(my_date_1) > DATE(my_date_2) ORDER BY DATE(my_date_3) DESC... And... you can check if is a zero date like WHERE my_date_1 = '0000-00-00 00:00:00'

    – Olaf Erlandsen
    Apr 24 '17 at 13:16













  • I get the data from SQL server and I pass it to mysql. The incoming date looks this way : '0000-00-00 00:00:00'. This is just a back up system, and I need to keep the data as it is in the source system

    – Rathi Rao
    Apr 24 '17 at 13:16











  • I cannot store the date in varchar as I cannot change the data type and I am not allowed to do it. And yeah, I did restart mysql after the changes

    – Rathi Rao
    Apr 24 '17 at 13:20














2












2








2








I want zero dates to be allowed in MySQL. I have changed the sql_mode to ALLOW_INVALID_DATES,NO_ENGINE_SUBSTITUTION.



I have changed it in /etc/mysql/my.cnf.



Yet, I when I try to insert data I get the error,




Data truncation: Incorrect datetime value: '0000-00-00 00:00:00'




The MySQL version is 5.7.18.



Any ideas on this would be of great help.










share|improve this question
















I want zero dates to be allowed in MySQL. I have changed the sql_mode to ALLOW_INVALID_DATES,NO_ENGINE_SUBSTITUTION.



I have changed it in /etc/mysql/my.cnf.



Yet, I when I try to insert data I get the error,




Data truncation: Incorrect datetime value: '0000-00-00 00:00:00'




The MySQL version is 5.7.18.



Any ideas on this would be of great help.







mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 24 '17 at 15:46









johnnyRose

4,141113552




4,141113552










asked Apr 24 '17 at 13:11









Rathi RaoRathi Rao

12219




12219








  • 2





    What data were you inserting when this error happened? Why do you need to allow invalid dates?

    – Tim Biegeleisen
    Apr 24 '17 at 13:13






  • 1





    Did you restart the server?

    – Igor
    Apr 24 '17 at 13:14











  • Well, I think in varchar field. So, why you don't use varchar? when you execute select, update, delete, ... you can convert with DATE() like SELECT id FROM my_table where DATE(my_date_1) > DATE(my_date_2) ORDER BY DATE(my_date_3) DESC... And... you can check if is a zero date like WHERE my_date_1 = '0000-00-00 00:00:00'

    – Olaf Erlandsen
    Apr 24 '17 at 13:16













  • I get the data from SQL server and I pass it to mysql. The incoming date looks this way : '0000-00-00 00:00:00'. This is just a back up system, and I need to keep the data as it is in the source system

    – Rathi Rao
    Apr 24 '17 at 13:16











  • I cannot store the date in varchar as I cannot change the data type and I am not allowed to do it. And yeah, I did restart mysql after the changes

    – Rathi Rao
    Apr 24 '17 at 13:20














  • 2





    What data were you inserting when this error happened? Why do you need to allow invalid dates?

    – Tim Biegeleisen
    Apr 24 '17 at 13:13






  • 1





    Did you restart the server?

    – Igor
    Apr 24 '17 at 13:14











  • Well, I think in varchar field. So, why you don't use varchar? when you execute select, update, delete, ... you can convert with DATE() like SELECT id FROM my_table where DATE(my_date_1) > DATE(my_date_2) ORDER BY DATE(my_date_3) DESC... And... you can check if is a zero date like WHERE my_date_1 = '0000-00-00 00:00:00'

    – Olaf Erlandsen
    Apr 24 '17 at 13:16













  • I get the data from SQL server and I pass it to mysql. The incoming date looks this way : '0000-00-00 00:00:00'. This is just a back up system, and I need to keep the data as it is in the source system

    – Rathi Rao
    Apr 24 '17 at 13:16











  • I cannot store the date in varchar as I cannot change the data type and I am not allowed to do it. And yeah, I did restart mysql after the changes

    – Rathi Rao
    Apr 24 '17 at 13:20








2




2





What data were you inserting when this error happened? Why do you need to allow invalid dates?

– Tim Biegeleisen
Apr 24 '17 at 13:13





What data were you inserting when this error happened? Why do you need to allow invalid dates?

– Tim Biegeleisen
Apr 24 '17 at 13:13




1




1





Did you restart the server?

– Igor
Apr 24 '17 at 13:14





Did you restart the server?

– Igor
Apr 24 '17 at 13:14













Well, I think in varchar field. So, why you don't use varchar? when you execute select, update, delete, ... you can convert with DATE() like SELECT id FROM my_table where DATE(my_date_1) > DATE(my_date_2) ORDER BY DATE(my_date_3) DESC... And... you can check if is a zero date like WHERE my_date_1 = '0000-00-00 00:00:00'

– Olaf Erlandsen
Apr 24 '17 at 13:16







Well, I think in varchar field. So, why you don't use varchar? when you execute select, update, delete, ... you can convert with DATE() like SELECT id FROM my_table where DATE(my_date_1) > DATE(my_date_2) ORDER BY DATE(my_date_3) DESC... And... you can check if is a zero date like WHERE my_date_1 = '0000-00-00 00:00:00'

– Olaf Erlandsen
Apr 24 '17 at 13:16















I get the data from SQL server and I pass it to mysql. The incoming date looks this way : '0000-00-00 00:00:00'. This is just a back up system, and I need to keep the data as it is in the source system

– Rathi Rao
Apr 24 '17 at 13:16





I get the data from SQL server and I pass it to mysql. The incoming date looks this way : '0000-00-00 00:00:00'. This is just a back up system, and I need to keep the data as it is in the source system

– Rathi Rao
Apr 24 '17 at 13:16













I cannot store the date in varchar as I cannot change the data type and I am not allowed to do it. And yeah, I did restart mysql after the changes

– Rathi Rao
Apr 24 '17 at 13:20





I cannot store the date in varchar as I cannot change the data type and I am not allowed to do it. And yeah, I did restart mysql after the changes

– Rathi Rao
Apr 24 '17 at 13:20












5 Answers
5






active

oldest

votes


















1














You might want to read about other mode settings, such as strict and NO_ZERO_IN_DATE and NO_ZERO_DATE https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date






share|improve this answer































    0














    I am going to assume here that you want to have a valid date so that your queries never have to check for NULL.



    One way to do this, is to use what I like to call "In perpetuity" date(s).



    These are essentially the min/max dates allowable for the DATETIME data type.



    In my uses, there were typically "windows" of from - to pairs, but you might only need the minimum date.



    From the Mysql manual:




    The DATETIME type is used for values that contain both date and time
    parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD
    HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to
    '9999-12-31 23:59:59'.




    So one way that might work for you, is to utilize '1000-01-01 00:00:00' instead of the zero date.






    share|improve this answer































      0














      I could solve this by using zeroDateTimeBehavior=convertToNull






      share|improve this answer































        0














        To allow zero dates (0000-00-00 00:00:00), you need to remove that restriction.



        To remove particular SQL mode (in this case NO_ZERO_DATE), find the current SQL mode:



        SELECT @@GLOBAL.sql_mode;


        copy the result and remove from it what you don't need (NO_ZERO_DATE)



        e.g.:



        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


        to



        ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


        create and open this file:



        sudo vim /etc/mysql/conf.d/disable_strict_mode.cnf


        and write and past into it your new SQL mode:



        [mysqld]
        sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


        restart MySQL:



        sudo service mysql restart





        share|improve this answer































          -1














          It should go without saying that you're doing it wrong. The column should be nullable if you intend to store nothing, and you shouldn't try to insert an empty string when you should be using a NULL.



          Consider this, though:



          If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings.
          But when strict mode is in effect...



          For transactional tables, an error occurs for invalid or missing values in a data-change statement when either STRICT_ALL_TABLES or STRICT_TRANS_TABLES is enabled. The statement is aborted and rolled back



          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
          SELECT @@SQL_MODE; should reveal that you are running with (at least) STRICT_TRANS_TABLES. While this isn't the internal default in 5.6, it is included in the default 5.6 configuration file. You'll want to remove it and restart the server if you want the old behavior.



          ...although you should consider making your code behave more correctly.



          Try enabling this



          ALLOW_INVALID_DATES



          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sqlmode_allow_invalid_dates



          Note: I do not recommend doing this. I'm just answering how to do it. In my opinion, it is better to clean up the queries and data, and provide a good default for columns that are non-null.






          share|improve this answer
























          • The OP has already enabled ALLOW_INVALID_DATES. That's exactly the question: ALLOW_INVALID_DATES is enabled, yet MySQL provides an error when a zero date is used.

            – Shadow
            Apr 24 '17 at 13:39











          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%2f43589048%2fmysql-need-to-allow-0000-00-00-000000-dates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You might want to read about other mode settings, such as strict and NO_ZERO_IN_DATE and NO_ZERO_DATE https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date






          share|improve this answer




























            1














            You might want to read about other mode settings, such as strict and NO_ZERO_IN_DATE and NO_ZERO_DATE https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date






            share|improve this answer


























              1












              1








              1







              You might want to read about other mode settings, such as strict and NO_ZERO_IN_DATE and NO_ZERO_DATE https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date






              share|improve this answer













              You might want to read about other mode settings, such as strict and NO_ZERO_IN_DATE and NO_ZERO_DATE https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Apr 24 '17 at 14:55









              Peter GulutzanPeter Gulutzan

              31613




              31613

























                  0














                  I am going to assume here that you want to have a valid date so that your queries never have to check for NULL.



                  One way to do this, is to use what I like to call "In perpetuity" date(s).



                  These are essentially the min/max dates allowable for the DATETIME data type.



                  In my uses, there were typically "windows" of from - to pairs, but you might only need the minimum date.



                  From the Mysql manual:




                  The DATETIME type is used for values that contain both date and time
                  parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD
                  HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to
                  '9999-12-31 23:59:59'.




                  So one way that might work for you, is to utilize '1000-01-01 00:00:00' instead of the zero date.






                  share|improve this answer




























                    0














                    I am going to assume here that you want to have a valid date so that your queries never have to check for NULL.



                    One way to do this, is to use what I like to call "In perpetuity" date(s).



                    These are essentially the min/max dates allowable for the DATETIME data type.



                    In my uses, there were typically "windows" of from - to pairs, but you might only need the minimum date.



                    From the Mysql manual:




                    The DATETIME type is used for values that contain both date and time
                    parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD
                    HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to
                    '9999-12-31 23:59:59'.




                    So one way that might work for you, is to utilize '1000-01-01 00:00:00' instead of the zero date.






                    share|improve this answer


























                      0












                      0








                      0







                      I am going to assume here that you want to have a valid date so that your queries never have to check for NULL.



                      One way to do this, is to use what I like to call "In perpetuity" date(s).



                      These are essentially the min/max dates allowable for the DATETIME data type.



                      In my uses, there were typically "windows" of from - to pairs, but you might only need the minimum date.



                      From the Mysql manual:




                      The DATETIME type is used for values that contain both date and time
                      parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD
                      HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to
                      '9999-12-31 23:59:59'.




                      So one way that might work for you, is to utilize '1000-01-01 00:00:00' instead of the zero date.






                      share|improve this answer













                      I am going to assume here that you want to have a valid date so that your queries never have to check for NULL.



                      One way to do this, is to use what I like to call "In perpetuity" date(s).



                      These are essentially the min/max dates allowable for the DATETIME data type.



                      In my uses, there were typically "windows" of from - to pairs, but you might only need the minimum date.



                      From the Mysql manual:




                      The DATETIME type is used for values that contain both date and time
                      parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD
                      HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to
                      '9999-12-31 23:59:59'.




                      So one way that might work for you, is to utilize '1000-01-01 00:00:00' instead of the zero date.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 24 '17 at 16:01









                      gviewgview

                      11.2k22639




                      11.2k22639























                          0














                          I could solve this by using zeroDateTimeBehavior=convertToNull






                          share|improve this answer




























                            0














                            I could solve this by using zeroDateTimeBehavior=convertToNull






                            share|improve this answer


























                              0












                              0








                              0







                              I could solve this by using zeroDateTimeBehavior=convertToNull






                              share|improve this answer













                              I could solve this by using zeroDateTimeBehavior=convertToNull







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 12 '18 at 8:05









                              Rathi RaoRathi Rao

                              12219




                              12219























                                  0














                                  To allow zero dates (0000-00-00 00:00:00), you need to remove that restriction.



                                  To remove particular SQL mode (in this case NO_ZERO_DATE), find the current SQL mode:



                                  SELECT @@GLOBAL.sql_mode;


                                  copy the result and remove from it what you don't need (NO_ZERO_DATE)



                                  e.g.:



                                  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


                                  to



                                  ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                  create and open this file:



                                  sudo vim /etc/mysql/conf.d/disable_strict_mode.cnf


                                  and write and past into it your new SQL mode:



                                  [mysqld]
                                  sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                  restart MySQL:



                                  sudo service mysql restart





                                  share|improve this answer




























                                    0














                                    To allow zero dates (0000-00-00 00:00:00), you need to remove that restriction.



                                    To remove particular SQL mode (in this case NO_ZERO_DATE), find the current SQL mode:



                                    SELECT @@GLOBAL.sql_mode;


                                    copy the result and remove from it what you don't need (NO_ZERO_DATE)



                                    e.g.:



                                    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


                                    to



                                    ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                    create and open this file:



                                    sudo vim /etc/mysql/conf.d/disable_strict_mode.cnf


                                    and write and past into it your new SQL mode:



                                    [mysqld]
                                    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                    restart MySQL:



                                    sudo service mysql restart





                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      To allow zero dates (0000-00-00 00:00:00), you need to remove that restriction.



                                      To remove particular SQL mode (in this case NO_ZERO_DATE), find the current SQL mode:



                                      SELECT @@GLOBAL.sql_mode;


                                      copy the result and remove from it what you don't need (NO_ZERO_DATE)



                                      e.g.:



                                      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


                                      to



                                      ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                      create and open this file:



                                      sudo vim /etc/mysql/conf.d/disable_strict_mode.cnf


                                      and write and past into it your new SQL mode:



                                      [mysqld]
                                      sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                      restart MySQL:



                                      sudo service mysql restart





                                      share|improve this answer













                                      To allow zero dates (0000-00-00 00:00:00), you need to remove that restriction.



                                      To remove particular SQL mode (in this case NO_ZERO_DATE), find the current SQL mode:



                                      SELECT @@GLOBAL.sql_mode;


                                      copy the result and remove from it what you don't need (NO_ZERO_DATE)



                                      e.g.:



                                      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


                                      to



                                      ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                      create and open this file:



                                      sudo vim /etc/mysql/conf.d/disable_strict_mode.cnf


                                      and write and past into it your new SQL mode:



                                      [mysqld]
                                      sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


                                      restart MySQL:



                                      sudo service mysql restart






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 20 at 14:21









                                      WaqlehWaqleh

                                      4,61385084




                                      4,61385084























                                          -1














                                          It should go without saying that you're doing it wrong. The column should be nullable if you intend to store nothing, and you shouldn't try to insert an empty string when you should be using a NULL.



                                          Consider this, though:



                                          If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings.
                                          But when strict mode is in effect...



                                          For transactional tables, an error occurs for invalid or missing values in a data-change statement when either STRICT_ALL_TABLES or STRICT_TRANS_TABLES is enabled. The statement is aborted and rolled back



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
                                          SELECT @@SQL_MODE; should reveal that you are running with (at least) STRICT_TRANS_TABLES. While this isn't the internal default in 5.6, it is included in the default 5.6 configuration file. You'll want to remove it and restart the server if you want the old behavior.



                                          ...although you should consider making your code behave more correctly.



                                          Try enabling this



                                          ALLOW_INVALID_DATES



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sqlmode_allow_invalid_dates



                                          Note: I do not recommend doing this. I'm just answering how to do it. In my opinion, it is better to clean up the queries and data, and provide a good default for columns that are non-null.






                                          share|improve this answer
























                                          • The OP has already enabled ALLOW_INVALID_DATES. That's exactly the question: ALLOW_INVALID_DATES is enabled, yet MySQL provides an error when a zero date is used.

                                            – Shadow
                                            Apr 24 '17 at 13:39
















                                          -1














                                          It should go without saying that you're doing it wrong. The column should be nullable if you intend to store nothing, and you shouldn't try to insert an empty string when you should be using a NULL.



                                          Consider this, though:



                                          If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings.
                                          But when strict mode is in effect...



                                          For transactional tables, an error occurs for invalid or missing values in a data-change statement when either STRICT_ALL_TABLES or STRICT_TRANS_TABLES is enabled. The statement is aborted and rolled back



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
                                          SELECT @@SQL_MODE; should reveal that you are running with (at least) STRICT_TRANS_TABLES. While this isn't the internal default in 5.6, it is included in the default 5.6 configuration file. You'll want to remove it and restart the server if you want the old behavior.



                                          ...although you should consider making your code behave more correctly.



                                          Try enabling this



                                          ALLOW_INVALID_DATES



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sqlmode_allow_invalid_dates



                                          Note: I do not recommend doing this. I'm just answering how to do it. In my opinion, it is better to clean up the queries and data, and provide a good default for columns that are non-null.






                                          share|improve this answer
























                                          • The OP has already enabled ALLOW_INVALID_DATES. That's exactly the question: ALLOW_INVALID_DATES is enabled, yet MySQL provides an error when a zero date is used.

                                            – Shadow
                                            Apr 24 '17 at 13:39














                                          -1












                                          -1








                                          -1







                                          It should go without saying that you're doing it wrong. The column should be nullable if you intend to store nothing, and you shouldn't try to insert an empty string when you should be using a NULL.



                                          Consider this, though:



                                          If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings.
                                          But when strict mode is in effect...



                                          For transactional tables, an error occurs for invalid or missing values in a data-change statement when either STRICT_ALL_TABLES or STRICT_TRANS_TABLES is enabled. The statement is aborted and rolled back



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
                                          SELECT @@SQL_MODE; should reveal that you are running with (at least) STRICT_TRANS_TABLES. While this isn't the internal default in 5.6, it is included in the default 5.6 configuration file. You'll want to remove it and restart the server if you want the old behavior.



                                          ...although you should consider making your code behave more correctly.



                                          Try enabling this



                                          ALLOW_INVALID_DATES



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sqlmode_allow_invalid_dates



                                          Note: I do not recommend doing this. I'm just answering how to do it. In my opinion, it is better to clean up the queries and data, and provide a good default for columns that are non-null.






                                          share|improve this answer













                                          It should go without saying that you're doing it wrong. The column should be nullable if you intend to store nothing, and you shouldn't try to insert an empty string when you should be using a NULL.



                                          Consider this, though:



                                          If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings.
                                          But when strict mode is in effect...



                                          For transactional tables, an error occurs for invalid or missing values in a data-change statement when either STRICT_ALL_TABLES or STRICT_TRANS_TABLES is enabled. The statement is aborted and rolled back



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
                                          SELECT @@SQL_MODE; should reveal that you are running with (at least) STRICT_TRANS_TABLES. While this isn't the internal default in 5.6, it is included in the default 5.6 configuration file. You'll want to remove it and restart the server if you want the old behavior.



                                          ...although you should consider making your code behave more correctly.



                                          Try enabling this



                                          ALLOW_INVALID_DATES



                                          http://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sqlmode_allow_invalid_dates



                                          Note: I do not recommend doing this. I'm just answering how to do it. In my opinion, it is better to clean up the queries and data, and provide a good default for columns that are non-null.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Apr 24 '17 at 13:25









                                          Prem SarojanandPrem Sarojanand

                                          147




                                          147













                                          • The OP has already enabled ALLOW_INVALID_DATES. That's exactly the question: ALLOW_INVALID_DATES is enabled, yet MySQL provides an error when a zero date is used.

                                            – Shadow
                                            Apr 24 '17 at 13:39



















                                          • The OP has already enabled ALLOW_INVALID_DATES. That's exactly the question: ALLOW_INVALID_DATES is enabled, yet MySQL provides an error when a zero date is used.

                                            – Shadow
                                            Apr 24 '17 at 13:39

















                                          The OP has already enabled ALLOW_INVALID_DATES. That's exactly the question: ALLOW_INVALID_DATES is enabled, yet MySQL provides an error when a zero date is used.

                                          – Shadow
                                          Apr 24 '17 at 13:39





                                          The OP has already enabled ALLOW_INVALID_DATES. That's exactly the question: ALLOW_INVALID_DATES is enabled, yet MySQL provides an error when a zero date is used.

                                          – Shadow
                                          Apr 24 '17 at 13:39


















                                          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%2f43589048%2fmysql-need-to-allow-0000-00-00-000000-dates%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







                                          Popular posts from this blog

                                          Liquibase includeAll doesn't find base path

                                          How to use setInterval in EJS file?

                                          Petrus Granier-Deferre