Question

In RDS I recently created a dump of my prod db and created a temp MySQL 5.6 db using the below commands:

mysqldump -u user --password=password -h host db_name | gzip -c > mysql.sql.gz
gunzip mysql.sql.gz
mysql -u user --password=password -h host db_name < mysql.sql

Everything worked fine. The one issue I'm noticing is that my app (Django 1.4) creates timestamps that are defined as per below:

`last_modified` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP,

Previously in MySQL 5.5 this was fine. But in 5.6, the null for the last_modified is not being interpreted as the current value. Is there anyway to handle this issue? ALL of my models have this issue....

EDIT

I updated the above field to:

alter table my_table modify last_modified timestamp DEFAULT CURRENT_TIMESTAMP

but when inserting, Django has a null for that field. Previously the null translated to the current timestamp, now it's just showing as null in the field. Is there a way to force MySQL to interpret null as the current timestamp?

Was it helpful?

Solution

From MySQL docs Upgrading from MySQL 5.5 to 5.6

TIMESTAMP columns declared as NOT NULL and without an explicit DEFAULT clause are treated as having no default value. For inserted rows that specify no explicit value for such a column, the result depends on the SQL mode. If strict SQL mode is enabled, an error occurs. If strict SQL mode is not enabled, the column is assigned the implicit default of '0000-00-00 00:00:00' and a warning occurs. This is similar to how MySQL treats other temporal types such as DATETIME.

So you should set the CURRENT_TIMESTAMP as DEFAULT for this field, ON UPDATE isn't sufficient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top