Opened 10 years ago

Closed 10 years ago

#22356 closed Bug (fixed)

unique_together fails when referencing columns from base and child class

Reported by: Claus Conrad Owned by: Marc Egli
Component: Core (System checks) Version: 1.7-beta-1
Severity: Normal Keywords:
Cc: Shai Berger, adrien Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Not sure whether this bug belongs to "System checks", "ORM" or "Migrations", but thought I'd report it:

class Foo(models.Model):

url = models.URLField("URL", blank=True)

class Bar(Foo):

blip = models.CharField(max_length=10)
class Meta:

unique_together = (

'url',
'blip'

)

---

$ python manage.py check
System check identified no issues (0 silenced).

---

$ python manage.py makemigrations
$ python manage.py migrate

File "/usr/lib/python3.3/site-packages/Django-1.7b1-py3.3.egg/django/db/backends/utils.py", line 61, in execute

return self.cursor.execute(sql, params)

psycopg2.ProgrammingError: column "url" named in key does not exist

Change History (9)

comment:1 by Shai Berger, 10 years ago

Cc: Shai Berger added
Component: MigrationsCore (System checks)
Needs tests: set
Triage Stage: UnreviewedAccepted

This cannot work when you are using multi-table inheritance -- the two columns are in separate tables, and you cannot place a cross-table constraint.

This probably belongs in "system checks".

It can work if the parent is abstract.

(accepting based on report, with no attempt to reproduce)
(I am hesitant to mark it, not being familiar enough with the checks code, but this is probably an easy-pickings ticket)

comment:2 by adrien, 10 years ago

I'm able to reproduce.

comment:3 by adrien, 10 years ago

Cc: adrien added

comment:4 by adrien, 10 years ago

Component: Core (System checks)Migrations

Digging in the code, I would say this belongs to Migrations.

comment:5 by Shai Berger, 10 years ago

Component: MigrationsCore (System checks)

@adrien: for this to belong in migrations, you need to point out something that migrations could do to fix it.

Please leave this in "system checks" until you can produce an SQL snippet that works on some database backend, and creates the expected constraint.

comment:6 by Marc Egli, 10 years ago

Owner: changed from nobody to Marc Egli
Status: newassigned

comment:7 by Marc Egli, 10 years ago

Has patch: set
Triage Stage: AcceptedUnreviewed

comment:8 by andrewsg, 10 years ago

Triage Stage: UnreviewedReady for checkin

comment:9 by Simon Charette <charette.s@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 0bcc92c6917738caa2f08ec16d26fad62974fb47:

Fixed #22356 -- Added a check to make sure unique_together fields are local.

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