I have an admin users db, I want to create a column with type datetime for edits, to know when and admin acc was edited, I will introduce the time with php and MySQLi, im on phpmyadmin, when I try to create the column it says:
#1292 - Incorrect datetime value: '0000-00-00 00:00:00' for column 'editado' at row 1
MySQL code is:
ALTER TABLE `admins` ADD `editado` DATETIME NOT NULL AFTER `password`;
Tried to execute on SQL but nothing, how can I do this?
If the table is not empty when you add a column, you need to first add the column as NULLABLE, update all the records in the table assigning a value to the column, then you can change the column you added from NULLABLE to NOT NULL. So something like this should be done:
ALTER TABLE admins ADD editado DATETIME NULL AFTER password;
UPDATE admins SET editado = '1900-01-01 00:00:00';
ALTER TABLE admins MODIFY editado DATETIME NOT NULL;
Not sure if the last query is correct syntax as I don't write MySQL often but thats what should happen.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.