Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL CURRENT_TIMESTAMP require extra parentheses #40

Open
todorvelichkov opened this issue Jul 14, 2023 · 0 comments
Open

MySQL CURRENT_TIMESTAMP require extra parentheses #40

todorvelichkov opened this issue Jul 14, 2023 · 0 comments

Comments

@todorvelichkov
Copy link

When using the undocumented NOWlike so:

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant