Opened 11 years ago
Closed 11 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 , 11 years ago
Cc: | added |
---|---|
Component: | Migrations → Core (System checks) |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 11 years ago
Cc: | added |
---|
comment:4 by , 11 years ago
Component: | Core (System checks) → Migrations |
---|
Digging in the code, I would say this belongs to Migrations.
comment:5 by , 11 years ago
Component: | Migrations → 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 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 11 years ago
Has patch: | set |
---|---|
Triage Stage: | Accepted → Unreviewed |
Pull request: https://github.com/django/django/pull/2548
comment:8 by , 11 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:9 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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)