[patch] Leaving out ¨ordering¨ in OneToOne relationship causes bad SQL statement
|Reported by:||EABinGA||Owned by:||Russell Keith-Magee|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Using Trunk rev-1461:
Given the Model Foo:
from django.core import meta # Create your models here. class Bar(meta.Model): class META: admin = meta.Admin() bardata = meta.CharField(maxlength=200) def __repr__(self): return self.bardata class Baz(meta.Model): class META: admin = meta.Admin() bazdata = meta.CharField(maxlength=200) bar = meta.OneToOneField(Bar) def __repr__(self): return self.bazdata
When you select ¨baz¨ from the main admin interface:
You are greeted by the following:
OperationalError at /admin/foo/bazs/ no such column: foo_bars.id Request Method: GET Request URL: http://127.0.0.1:8080/admin/foo/bazs/ Exception Type: OperationalError Exception Value: no such column: foo_bars.id Exception Location: /usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/django/core/db/backends/sqlite3.py in execute, line 71
The offending SQL statement seems to be:
SELECT "foo_bazs"."bazdata","foo_bazs"."bar_id" FROM "foo_bazs" ORDER BY "foo_bars"."id" DESC
Explicitly including an ¨ordering¨ in the ¨baz¨ class fixes this problem, but it should work properly without one.
Upon creation of a ¨baz¨, the admin interface of ¨baz¨ shows a label of ¨ID¨ folowed by a dropdown list containing bars followed by what seems to be the PK of said bar. What is the purpose of that number? Is it supposed to be there.
Additionally, once a baz is saved, the dropdown list suggests, that corresponding bar for this baz can be changed, but saving the baz with a different bar does not seem to have any effect.
Change History (12)
comment:2 Changed 11 years ago by
|Summary:||Leaving out ¨ordering¨ in OneToOne relationship causes bad SQL statement → [patch] Leaving out ¨ordering¨ in OneToOne relationship causes bad SQL statement|