#22659: parent_link relationships ignored by migrations
---------------------------------+------------------------
     Reporter:  tbartelmess      |      Owner:  nobody
         Type:  Bug              |     Status:  new
    Component:  Migrations       |    Version:  1.7-beta-2
     Severity:  Release blocker  |   Keywords:
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+------------------------
 The parent_link property on OneToOne relationships is ignored by the
 migration system. This causes the database to end up with two parent
 relationships.

 For example if you have a model like this:

 {{{
 class Company(models.Model):
     name = models.CharField(max_length=100)

 class FooCompany(Company):
     parent_company = models.OneToOneField(Company, primary_key = True,
 parent_link=True)
 }}}

 without migrations the generated tables are correct


 {{{
 BEGIN;
 CREATE TABLE "foo_company" (
     "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
     "name" varchar(100) NOT NULL
 )
 ;
 CREATE TABLE "foo_foocompany" (
     "parent_company_id" integer NOT NULL PRIMARY KEY REFERENCES
 "foo_company" ("id")
 )
 ;

 COMMIT;
 }}}

 the migration system however ignores that there is a parent link set and
 generate the tables like this

 {{{
 CREATE TABLE "foo_company" (
     "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(100)
 NOT NULL
 );

 CREATE TABLE "foo_foocompany" (
     "company_ptr_id" integer NOT NULL UNIQUE REFERENCES "foo_company"
 ("id"),
     "parent_company_id" integer NOT NULL PRIMARY KEY REFERENCES
 "foo_company" ("id")
 );
 }}}

 I've categorized this as a blocker, because it makes parent_links
 unusable, since the ORM won't know about the additional 'company_ptr_id'
 column causing inserts to fail because of the NOT NULL violation on that
 column

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22659>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.a203cacb97d2d18ab9030a46897b97ab%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to