You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from django_add_default_value import AddDefaultValue, NOW
# ....
class Migration(migrations.Migration):
operations = [
# ...
AddDefaultValue(model_name="mymodel", name="updated_at", value=NOW)
# ....
]
Generates the following SQL:
ALTER TABLE `app_mymodel` ALTER COLUMN `updated_at` SET DEFAULT CURRENT_TIMESTAMP;
However on MySQL 8.0.33, this triggers the following error (I believe this behaviour starts from 8.0.13, but I'm not 100% sure):
django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURRENT_TIMESTAMP' at line 1")
The correct syntax is with extra parentheses around CURRENT_TIMESTAMP like so:
ALTER TABLE `app_mymodel` ALTER COLUMN `updated_at` SET DEFAULT (CURRENT_TIMESTAMP);
The text was updated successfully, but these errors were encountered:
When using the undocumented
NOW
like so:Generates the following SQL:
ALTER TABLE `app_mymodel` ALTER COLUMN `updated_at` SET DEFAULT CURRENT_TIMESTAMP;
However on MySQL 8.0.33, this triggers the following error (I believe this behaviour starts from 8.0.13, but I'm not 100% sure):
The correct syntax is with extra parentheses around
CURRENT_TIMESTAMP
like so:ALTER TABLE `app_mymodel` ALTER COLUMN `updated_at` SET DEFAULT (CURRENT_TIMESTAMP);
The text was updated successfully, but these errors were encountered: