Stop automatic updating for MySQL datestamp
Question
I have a datetime
column called create_date
. When I create a row, I enter the date NOW().
However, when I update a row my create_date
column automatically updates to NOW(). Even if I was setting different columns and not touching create_date
, it still gets updated. How can I stop this behavior?
Found this doc, but it doesn't explain how to stop the automatic updating. http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
Solution
Try changing the schema so that it uses the DEFAULT clause, which sets it on creation but not on an update:
ALTER TABLE tablename MODIFY COLUMN columnamre TIMESTAMP DEFAULT CURRENT_TIMESTAMP
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow