I have a db with the following Django Migrations:
0001_initial.py:
migrations.AddField(
model_name='extrashirtprice',
name='sibs_weekend',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='registration.SibsWeekend'),
),
So I want to make it a OneToOneField instead. So there's a new migration:
0012_auto.py:
operations = [
migrations.AlterField(
model_name='extrashirtprice',
name='sibs_weekend',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='registration.SibsWeekend'),
),
]
I checked and ensured that the operation done in 0012 wasn't done anywhere else.
When I run migrate, I get:
django.db.utils.ProgrammingError: relation "registration_extrashirtprice_sibs_weekend_id_6626038b_uniq" already exists
I looked at Django - Change a ForeignKey relation to OneToOne but they were talking about using --fake which would not actually apply the unique constraint. Plus we deploy with an automated script so I want to avoid adding commands if possible. This post also had no actual accepted answers and it was in the context of south migrations so I'd rather see how it can be done using Django migrations in a better way.
I could just use ForeignKey with a unique constraint (I assume) but I want to use the more official OneToOneField for this if possible.
NOTE: I am running these migrations on a database with data. It's not empty so if the issue has anything to do with the fact that there's data, please show me how to fix that since I don't want to lose production data.
Also, I am assuming in this that a OneToOneField is just a ForeignKey with a unique constraint. Please correct me if I'm wrong cause otherwise, this whole question is invalid.