Opened 6 years ago

Last modified 15 months ago

#29574 new Bug

Django Foreign Key Mismatch — at Initial Version

Reported by: josephbiko Owned by: nobody
Component: Migrations Version: 2.1
Severity: Normal Keywords:
Cc: josephbiko Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django Foreign key's do not track the models DB when the model is inherited from abstract class.

class A(Model):
   class Meta:
      abstract = True
class B(A):
   pass
class C(Model):
   fk = foreignkey(B,on_delete=models.CASCADE)

now model B is in table 1 and C points to table 1.

class A(Model):
   pass
class B(A):
   pass
class C(Model):
   fk = foreignkey(B,on_delete=models.CASCADE)

Now Model B is in table 2 with Model A, however C is still pointing to table 1, which leads to a foreign key mismatch error when you try to add an instance of B

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top