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 - migrate fails if ANSI or ANSI_QUOTES sql mode is set #475

Closed
MacTynow opened this issue Nov 18, 2020 · 0 comments · Fixed by #476
Closed

MySQL - migrate fails if ANSI or ANSI_QUOTES sql mode is set #475

MacTynow opened this issue Nov 18, 2020 · 0 comments · Fixed by #476

Comments

@MacTynow
Copy link
Contributor

MacTynow commented Nov 18, 2020

Describe the Bug
MySQL - migrate fails if ANSI or ANSI_QUOTES sql_mode is set with the following message:

error: Error 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 '"schema_migrations"' at line 1 in line 0: SHOW TABLES LIKE "schema_migrations"

Steps to Reproduce
Steps to reproduce the behavior:

  1. Set sql_mode on a mysql database to ANSI or ANSI_QUOTES
  2. Try to run migrate up
  3. Migrate fails to find the version tables and exits before doing anything

Expected Behavior
Migrate should just run normally and apply the migrations.

Migrate Version
v4.13.0

Additional context
The behavior of double quotes (") is different depending on the sql_mode that is set on a server (https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_ansi_quotes). In particular if ANSI_QUOTES is set:

Treat " as an identifier quote character (like the quote character) and not as a string quote character. You can still use to quote identifiers with this mode enabled. With ANSI_QUOTES enabled, you cannot use double quotation marks to quote literal strings because they are interpreted as identifiers.

As a consequence

query := `SHOW TABLES LIKE "` + m.config.MigrationsTable + `"`
errors out if that's set. I suggest replacing " by ' as suggested in https://stackoverflow.com/a/14123649 (as it is done here).

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

Successfully merging a pull request may close this issue.

1 participant