Samuel Loog
Samuel Loog

Reputation: 272

MySQL ALTER TABLE add column: error at another column

ok, i have people table and try run sql-script with the next command:

ALTER TABLE `people`
    ADD COLUMN `name_spelling`
    VARCHAR(255) NULL DEFAULT NULL
    AFTER `last_name`;

Then I'll get a error:

[22001][1292] Data truncation: Incorrect date value:
'0000-00-00' for column 'birth_date' at row 35

At this row birth_date is NULL, but if I try set some date like 2016-05-05 at this column and row and than set NULL back -- all works is correct at this row, but get error on some next null date.

In addition, not all null date values return error.

Upvotes: 0

Views: 1872

Answers (2)

chukwuka mark
chukwuka mark

Reputation: 164

I ran into this issue once and the fix i had was to to edit mysql.cnf file Replace : sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

with this : sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

Notice i removed the No_ZEROs in that options.

Upvotes: 0

Hugo St-Arnaud
Hugo St-Arnaud

Reputation: 169

Maybe your MySQL has some option such as the NO_ZERO_DATE SQL mode (I think it's not the only mysql config that prevents 0000-00-00 dates). This would prevent you from using 0000-00-00 as a value. It happened to me before that I had a table already created violating that condition. It will not be editable until you change the value or disable what's preventing you to set 0 dates.

For reference :http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

Upvotes: 1

Related Questions