Opened 2 years ago

Closed 2 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 Changed 2 years ago by Shai Berger

Cc: Shai Berger added
Component: MigrationsCore (System checks)
Needs documentation: unset
Needs tests: set
Patch needs improvement: unset
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 Changed 2 years ago by adrien

I'm able to reproduce.

comment:3 Changed 2 years ago by adrien

Cc: adrien added

comment:4 Changed 2 years ago by adrien

Component: Core (System checks)Migrations

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

comment:5 Changed 2 years ago by Shai Berger

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 Changed 2 years ago by Marc Egli

Owner: changed from nobody to Marc Egli
Status: newassigned

comment:7 Changed 2 years ago by Marc Egli

Has patch: set
Triage Stage: AcceptedUnreviewed

comment:8 Changed 2 years ago by andrewsg

Triage Stage: UnreviewedReady for checkin

comment:9 Changed 2 years ago by Simon Charette <charette.s@…>

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