﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22659	parent_link relationships ignored by migrations	tbartelmess	Simon Charette	"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"	Bug	closed	Migrations	1.7-beta-2	Release blocker	fixed			Ready for checkin	1	0	1	0	0	0
