Issue 109 in django-evolution: AddField: wrong columnname in SQL-statement (ForeignKey with OneToOne-Relation)

1 view
Skip to first unread message

codesite...@google.com

unread,
Oct 2, 2009, 7:41:40 AM10/2/09
to django-evolu...@googlegroups.com
Status: New
Owner: ----

New issue 109 by zegrep: AddField: wrong columnname in SQL-statement
(ForeignKey with OneToOne-Relation)
http://code.google.com/p/django-evolution/issues/detail?id=109

class Parent(models.Model):
...

class Child(Parent):
...

class Other(models.Model)
child=models.ForeignKey(Child)

> evolve --hint --sql

ALTER TABLE "test_other" ADD COLUMN "child" integer NOT NULL REFERENCES
"test_chil" ("child_ptr") DEFERRABLE INITIALLY DEFERRED;

--> "child_ptr" should be "child_ptr_id", because pk is a OneToOneField

SOLUTION: (using get_attname() from Field)

Index: django_evolution/db/common.py
===================================================================
--- django_evolution/db/common.py (Revision 166)
+++ django_evolution/db/common.py (Arbeitskopie)
@@ -46,7 +46,8 @@
# ALTER TABLE <tablename> ADD COLUMN <column name> NULL
REFERENCES <tablename1> ("<colname>") DEFERRABLE INITIALLY DEFERRED
related_model = f.rel.to
related_table = related_model._meta.db_table
- related_pk_col = related_model._meta.pk.name
+ related_pk_col =
related_model._meta.get_field(related_model._meta.pk.name).get_attname()


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

Reply all
Reply to author
Forward
0 new messages