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
{{ message }}
Repository navigation
Autogenerate creates duplicate commands for unique constraints #844
alembic revision --autogenerate creates duplicate lines for unique constraints in upgrade() method.
It does not affect actual upgrade in DB, but it looks strange in revision script.
Expected behavior
No duplicate records in revision script.
To Reproduce
After alembic init alembic I added the following code to alembic/env.py
changed the title [-]Autogenerate creates duplicate commands for constraints[/-][+]Autogenerate creates duplicate commands for unique constraints[/+]on May 19, 2021
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidForeignKey) there is no unique constraint matching given keys for referenced table "snapshots"
[SQL: ALTER TABLE runs ADD FOREIGN KEY(snapshot_id) REFERENCES snapshots (snapshot_id)]
--
I don't have a minimal repro for this but will try to get one in the next couple of days.
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidForeignKey) there is no unique constraint matching given keys for referenced table "snapshots"
[SQL: ALTER TABLE runs ADD FOREIGN KEY(snapshot_id) REFERENCES snapshots (snapshot_id)]
--
I don't have a minimal repro for this but will try to get one in the next couple of days.
Activity
[-]Autogenerate creates duplicate commands for constraints[/-][+]Autogenerate creates duplicate commands for unique constraints[/+]sqla-tester commentedon May 20, 2021
Mike Bayer has proposed a fix for this issue in the master branch:
Remove unique/index flags when copying table https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/2834
zzzeek commentedon May 20, 2021
thanks for reporting
mgasner commentedon May 24, 2021
Believe that this fix may have broken some previously valid migrations -- we have observed https://github.com/dagster-io/dagster/blob/master/python_modules/libraries/dagster-postgres/dagster_postgres/alembic/versions/c63a27054f08_add_snapshots_to_run_storage.py#L36 failing on alembic 1.6.3 (passes on 1.6.2) with the following:
I don't have a minimal repro for this but will try to get one in the next couple of days.
Pin alembic
zzzeek commentedon May 24, 2021
so crazy there were no tests for that, see #848
Repin alembic
Remove unique/index flags when copying table