문제

I wish to update my database (with already data in it), and add a column to a table

This new column is a date and I don't want it null nor having a default value.

Since I already have data in the database, mysql won't allow me to insert a not null data, so what I'm trying is to insert a column null possible, insert all my data, then set it to not null like so

ALTER TABLE `Test`.`rct` 
ADD COLUMN `dte` DATE NULL AFTER `id`;

--Insert logic here, and now every single rows has a value

ALTER TABLE `Test`.`rct` 
MODIFY `dte` DATE NOT NULL AFTER `id`;

But when I do this, I get this error on the: Incorrect date value: '0000-00-00' for column

But I check, and recheck, there is no 0000-00-00 value nowhere

So how can I set that column to null without setting it a default value?

Thank you.

도움이 되었습니까?

해결책

So, if when I don't modify the position (after id), for some reason, it will work!

ALTER TABLE `Test`.`rct` 
MODIFY `dte` DATE NOT NULL;

No idea why... but when I do a describe, I get exactly what I want.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top