This is largely for legacy databases, where column names were not capitalized
consistently.
class Parent(models.Model):
title = models.CharField(max_length=100, db_column="Title")
class Child(models.Model):
parent = models.ForeignKey(Parent, related_name="children")
title = models.CharField(max_length=100, db_column="title")
Child.objects.select_related("parent__pk").all()
This will generally result in
The column 'Title' was specified multiple times for 'X'
The problem is: according to Python, "Title" and "title" are distinct. So an
alias isn't being created, because it isn't needed. According to MS SQL,
however, they're the same.
The non-programmatic fix is to change the column names in the database so that
they share the same case, and have that reflect as well in the models:
class Parent(models.Model):
title = models.CharField(max_length=100, db_column="title")
class Child(models.Model):
parent = models.ForeignKey(Parent, related_name="children")
title = models.CharField(max_length=100, db_column="title")
However, a better fix would be for django-pyodbc to be adjusted to account for
the fact that MSSQL isn't case sensitive. Fields that match on a
case-insensitive level should become aliases.
Original issue reported on code.google.com by jordanth...@gmail.com on 2 Sep 2011 at 6:12
Original issue reported on code.google.com by
jordanth...@gmail.com
on 2 Sep 2011 at 6:12