[Django]-Removing Unique_together relationship from class Meta?

4👍

Commenting in models.py will not help here as migrations work if only it sees an alteration in relations and their attributes you create. unique_together is a constraint and migrations don’t detect them if you just comment.

I am hoping you still have your migrations folder and all generated migrations intact.

If anything is messed up too badly and you are on your own developer environment which does not disturb anyone else, go ahead and clear all migrations and just reset the db.

Else Here is what you can try if you still have migrations and don’t want to delete them.
Steps :

  • goto migrations file which has migrations.AlterUniqueTogether the first time in list of all migration files done, and comment that and all subsequent occurrence.
  • login to psql shell and to your database. Use \d+ <table name> to see all indexes and constraints. Find the one constraint which has ("basket", "line_reference"). Drop it. Command would be ALTER TABLE <table_name> DROP CONSTRAINT <name_of_constraint>
  • Now just run migrate <app_name> OR migrate

Hope this works.

Leave a comment