-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix foreign key issue in migration #1107
base: master
Are you sure you want to change the base?
Conversation
I think you have added those indices throught schema.rb or some other way. Can you reproduce it in a empty database/project ? |
mm but what's the point of trying on an empty DB? Gems are usually added to existing projects with populated DBs, no? |
If the tagging tables/relations existed in the database, that mean the migrations will fail. |
This is an issue on a new DB as well (I just ran across it). It is because the previous migration does this:
Which creates a foreign key which must be removed first. I added the line as per this PR and it fixed it. |
Would love to see this merged. + to the last comment. MySQL will create this index by default since it's a foreign key: |
@seuros what do you think? |
Looks like it's a problem on both new and populated DBs, I only see advantages in implementing this change. |
Hey, I've noticed that if we run the migrations generated by this gem using a MySQL database we get an error that prevents the migration from being run successfully.
Specifically, when the
AddMissingUniqueIndices
migration runs, we try to remove thetag_id
index from thetaggings
table, but it fails because we have the foreign key ontags(id)
.I've encountered this problem with MySQL 5.7 (the most used nowadays), 8.0.32, and 8.0.33.
This is the error:
With this fix we remove the foreign key before the offending line, and add it again at the end, after we create the compound index.