#22356 closed Bug (fixed)

unique_together fails when referencing columns from base and child class

Reported by: claus Owned by: frog32
Component: Core (System checks) Version: 1.7-beta-1
Severity: Normal Keywords:
Cc: shai, 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 15 months ago by shai

  • Cc shai added
  • Component changed from Migrations to Core (System checks)
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 15 months ago by adrien

I'm able to reproduce.

comment:3 Changed 15 months ago by adrien

  • Cc adrien added

comment:4 Changed 15 months ago by adrien

  • Component changed from Core (System checks) to Migrations

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

comment:5 Changed 15 months ago by shai

  • Component changed from Migrations to Core (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 15 months ago by frog32

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

comment:7 Changed 15 months ago by frog32

  • Has patch set
  • Triage Stage changed from Accepted to Unreviewed

comment:8 Changed 15 months ago by andrewsg

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:9 Changed 15 months ago by Simon Charette <charette.s@…>

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

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