Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#23013 closed Bug (fixed)

Removing unique_together constraint from model fails

Reported by: melinath Owned by: timo
Component: Migrations Version: 1.7-rc-1
Severity: Release blocker Keywords:
Cc: melinath Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This actually fails in two places. In both cases, it is because unique_together is being set to None, and things expect it to be a list.

First, in trying to create the migration.

# django/django/db/migrations/operations/models.py, line 251
# This fails
return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.unique_together))

# Should be
return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.unique_together) if self.unique_together is not None else 0)

Second, in trying to *run* the migration (if you fix the first issue or manually create a migration.

# django/django/db/migrations/state.py, line 276
# This fails
meta_contents["unique_together"] = list(meta_contents["unique_together"])

# Should be
meta_contents["unique_together"] = list(meta_contents["unique_together"]) if meta_contents["unique_together"] is not None else None

Attachments (1)

23013.diff (3.0 KB) - added by timo 10 months ago.
Still need to add a test for changes to state.py

Download all attachments as: .zip

Change History (6)

Changed 10 months ago by timo

Still need to add a test for changes to state.py

comment:1 Changed 10 months ago by timo

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Will try to finish tomorrow if no one beats me to it.

comment:2 Changed 10 months ago by timo

  • Owner changed from nobody to timo
  • Status changed from new to assigned

comment:3 Changed 10 months ago by timo

  • Needs tests unset

comment:4 Changed 10 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 015496539247b24c73b163f279ae8c8d3ccefc4c:

Fixed #23013 -- Fixed removing unique_together/index_together constraints in migrations.

Thanks melinath for the report.

comment:5 Changed 10 months ago by Tim Graham <timograham@…>

In 01515ebaa45a7facc6b450f3fea77dcdbec85887:

[1.7.x] Fixed #23013 -- Fixed removing unique_together/index_together constraints in migrations.

Thanks melinath for the report.

Backport of 0154965392 from master

Note: See TracTickets for help on using tickets.
Back to Top