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
Autogenerate wants to add existing indexes #202
Comments
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: OK I guess what we can do is for those indexes we found on the reflected side, remove the same ones from the metadata side as well. that would allow some support for detecting an "add" of these indexes. As you can see in the comment, MySQL has implicit column-named indexes placed on FK columns anyway, your approach hasn't run into problems with that ? |
Sjoerd Langkemper wrote: You mean that MySQL would complain because it creates an index and we create the same index. We have not encountered any problems, maybe because the table and index are added in the same migration:
|
Michael Bayer (@zzzeek) wrote:
→ 55d97db |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: OK so this will no longer report an "add" when there isn't one, and it will still detect an actual "add" of such an index. We just can't detect when such an index is "dropped" because when we see it on the backend, we don't know if that index is an implicitly generated one or not. |
Migrated issue, originally created by Sjoerd Langkemper
The autogenerate functionality adds indexes that already exist, if the index name is the same as the column name.
We have explicit indexes in our metadata.py with the same name as the column:
When using
alembic revision --autogenerate
, alembic wants to add this index to the database, even though it already exists.The index is correctly detected by Inspector.get_indexes, but then removed from the
conn_indexes
list byMySQLImpl.correct_for_autogen_constraints
. This method removes all indexes where the name is equal to the first column. The result is that the index is created in theupgrade
method of the migration:Running this migration gives an error:
It would be ok if
_compare_indexes_and_uniques
ignores these indexes, but it has to do so on the metadata side as well as the database side. Currently it pretends the indexes on the database don't exist, and tries to add them, which gives an error.The text was updated successfully, but these errors were encountered: