Hi Rui, Sounds like a bug to me; please open a ticket describing the problem you have found.
Yours, Russ Magee %-) On Friday, 13 April 2012 at 12:48 AM, Rui Silva wrote: > Hi, > > I was working with django 1.3.1 and oracle and i got this error: > ORA-00918: column ambiguously defined. > After some digging in django/db/models/sql/compiler.py i discovered > the bug/error: > > My models had a definition according to django sujested naming: > > class SampleModel(models.Model): > my_custom_id = models.AutoField('ID', db_column='MY_CUSTOM_ID' > primary_key=True) > field2 = models... > > class RelatedSampleModel(models.Model): > id = models.AutoField('ID', primary_key=True) > sample_model = models.ForeignKey(SampleModel) > > As it happens, when we make a query that involves select_related, the > generated query WILL NOT create a column alias for the my_custom_id > column and we will have something like: > > SELECT * FROM ( > SELECT ROWNUM AS "_RN", "_SUB".* FROM ( > SELECT > "SAMPLE_MODEL"."MY_CUSTOM_ID", > "SAMPLE_MODEL"."FIELD2...", > "RELATED_SAMPLE_MODEL"."ID", > > "RELATED_SAMPLE_MODEL"."MY_CUSTOM_ID" > FROM "REL" > INNER JOIN ".....)) "_SUB" WHERE ROWNUM <= 21) WHERE > "_RN" > 0' > > > The problem was the definition of the db_column in uppercase and the > foreignkey as a regular model field, witch resulted in a lowercase > column name in the sql generator. > I solved this error by changing all the names to lowercase. After > that, django correctly defined the column alias: > "RELATED_SAMPLE_MODEL"."MY_CUSTOM_ID" as Col20 > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com > (mailto:django-users@googlegroups.com). > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > (mailto:django-users+unsubscr...@googlegroups.com). > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.