How do I fix this MYSQL//Phpmyadmin error?

CHUCKVM25

So I tried to do a ALTER TABLE command to my table to add a date column that stores what time a post was made. Whenever I enter the SQL code, it pops up this error in PhpMyAdmin. I'm a beginner and I would really like if someone could help me.

Original code:

ALTER TABLE posts 
ADD date datetime not null;

Error that pops up: #1292 - Incorrect date value: '0000-00-00' for column 'website' . 'posts' . 'date' at row 1

ProGu

Give a default value

ALTER TABLE posts ADD `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP

Or if default value is not desired, add the column allowing NULL, update with appropriate values, and change the column to NOT NULL

ALTER TABLE posts ADD `date` datetime
;
UPDATE posts 
SET `date` = NOW() -- or any suitable values
;
ALTER TABLE posts CHANGE `date` `date` datetime NOT NULL
;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related