aerich icon indicating copy to clipboard operation
aerich copied to clipboard

Changing OneToOneField to ForeignKeyField generates broken SQL

Open mo-rijndael opened this issue 3 years ago • 0 comments

What I done to make it happen

  1. Make model which references other model as One2One. One2One is implemented via foreign + unique
  2. Migrate & apply changes to db
  3. Change field type to ForeignKeyField and migrate

Expected results

Upgrade: alter table ... drop constraint <unique_constrait>; Downgrade: alter table add constraint ...;

Actual results

Upgrade: aerich tries to drop non-existing index (dropping existing one will not work anyway) and then create new foreign key constraint (ignoring already existing) Downgrade: drop duplicated constraint + CREATE UNIQUE INDEX ...

Environment info

I'm using latest aerich from PyPI (0.7.1) and PostgreSQL 15

mo-rijndael avatar Jan 28 '23 09:01 mo-rijndael