Ticket #1049 (closed defect: duplicate)

Opened 3 years ago

Last modified 14 months ago

unique_together ordering

Reported by: George Lund <glund@…> Owned by: andrew
Priority: major Milestone: 1.0
Component: commands Version: unknown
Keywords: Cc:

Description

I am trying to add a unique_together constraint to a table.

The fields are listed in specific order, because the index that is created will perform properly only if the fields are in that order. So South needs to respect the order given in each tuple.

The fields are coming out in the right order in the freezer, so it must be something after that I guess (changes.py?).

Change History

comment:1 Changed 3 years ago by andrew

  • Status changed from new to accepted
  • Milestone set to 1.0

Hmm, I'm not aware of anything that changes the ordering, but I haven't looked in there
for a while.

In the meantime, just change the ordering yourself in the migration file.

comment:2 Changed 2 years ago by leftmoose <leftmoose@…>

i'm seeing a problem which is probably related. see e.g. sentry

https://github.com/dcramer/sentry/blob/917f1516ad1693113947ab6705e10fc31f023a42/sentry/migrations/0014_auto__add_project__add_projectmember__add_unique_projectmember_project.py#L85

https://github.com/dcramer/sentry/blob/917f1516ad1693113947ab6705e10fc31f023a42/sentry/migrations/0015_auto__add_field_message_project__add_field_messagecountbyminute_projec.py#L17

(the order of the fields in unique_together is reversed when the command to drop the index is generated)

at least for sqlite, this meant that the old index is left in the db

looks like the culprit may be in changes.py:

old_unique_together = map(set, old_unique_together)
new_unique_together = map(set, new_unique_together)

comment:3 Changed 14 months ago by Mike Fogel <mike@…>

This is duplicated by #1273, which has been resolved.

comment:4 Changed 14 months ago by andrew

  • Status changed from accepted to closed
  • Resolution set to duplicate
Note: See TracTickets for help on using tickets.