Modify ↓
Ticket #229 (closed defect: invalid)
inherited model m2m gets invalid foreign key
| Reported by: | iacobs+south@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.6.1 |
| Component: | migrations | Version: | 0.6 |
| Keywords: | Cc: |
Description
example:
class Person(models.Model):
name = models.CharField(max_length=10)
class Student(Person):
classes = models.ManyToManyField(Class)
will yield something like
db.create_table('people_student', (
('person_ptr', orm['people.Student:person_ptr']),
))
db.create_table('people_student_classes', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('student', models.ForeignKey(orm.Student, null=False)),
('class', models.ForeignKey(orm.Class, null=False)),
))
where the student foreign key erroneously points to Student.id instead of Student.person_ptr
Attachments
Change History
comment:2 Changed 4 years ago by andrew
It works for me:
$ ./manage.py migrate southdemo --verbosity=2
Running migrations for southdemo:
- Migrating forwards to 0006_test.
> southdemo: 0006_test
= CREATE TABLE "southdemo_person" ("id" serial NOT NULL PRIMARY KEY, "name" varchar(10) NOT NULL); []
= CREATE TABLE "southdemo_student" ("person_ptr_id" integer NOT NULL PRIMARY KEY); []
= CREATE TABLE "southdemo_student_classes" ("id" serial NOT NULL PRIMARY KEY, "student_id" integer NOT NULL, "lizard_id" integer NOT NULL); []
= ALTER TABLE "southdemo_lizard" ADD CONSTRAINT "southdemo_lizard_length" UNIQUE ("length") []
= ALTER TABLE "southdemo_student" ADD CONSTRAINT "person_ptr_id_refs_id_60924bac312951aa" FOREIGN KEY ("person_ptr_id") REFERENCES "southdemo_person" ("id") DEFERRABLE INITIALLY DEFERRED; []
= ALTER TABLE "southdemo_student_classes" ADD CONSTRAINT "student_id_refs_person_ptr_id_3fc13d2cae98a93c" FOREIGN KEY ("student_id") REFERENCES "southdemo_student" ("person_ptr_id") DEFERRABLE INITIALLY DEFERRED; []
= CREATE INDEX "southdemo_student_classes_student_id" ON "southdemo_student_classes" ("student_id"); []
= ALTER TABLE "southdemo_student_classes" ADD CONSTRAINT "lizard_id_refs_id_679dddb4f7a967a6" FOREIGN KEY ("lizard_id") REFERENCES "southdemo_lizard" ("id") DEFERRABLE INITIALLY DEFERRED; []
= CREATE INDEX "southdemo_student_classes_lizard_id" ON "southdemo_student_classes" ("lizard_id"); []
Are you on the very latest code? If you are and it still fails, I'd appreciate your output from "./manage.py migrate appname migrationname --verbosity=2".
Note: See
TracTickets for help on using
tickets.

Hrm, sounds nasty, but I was sure I'd fixed this. Will investigate later.