Reputation: 177
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.
Upvotes: 0
Views: 5572
Reputation: 177
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.
Upvotes: 0