Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23013 closed Bug (fixed)

Removing unique_together constraint from model fails

Reported by: Stephen Burrows Owned by: Tim Graham
Component: Migrations Version: 1.7-rc-1
Severity: Release blocker Keywords:
Cc: Stephen Burrows 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 Tim Graham 10 years ago.
Still need to add a test for changes to state.py

Download all attachments as: .zip

Change History (6)

by Tim Graham, 10 years ago

Attachment: 23013.diff added

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

comment:1 by Tim Graham, 10 years ago

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

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

comment:2 by Tim Graham, 10 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:3 by Tim Graham, 10 years ago

Needs tests: unset

comment:4 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 015496539247b24c73b163f279ae8c8d3ccefc4c:

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

Thanks melinath for the report.

comment:5 by Tim Graham <timograham@…>, 10 years ago

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