[Answered ]-2 OneToOneField defined for two tables. One got deleted but not other

2๐Ÿ‘

โœ…

If I have understood what you have posted correctly, you are better off with a design like this.

class Student(models.Model):
    id = models.IntegerField(primary_key=True)
    school = models.ForeignKey(SchoolMaster, on_delete=models.CASCADE)
    parent = models.ForeignKey(ParentMaster, on_delete=models.CASCADE)
    rf = models.CharField(max_length=30, primary_key=True)

This is essentially, your old StudentMaster model. I have renamed it to Student. I have also renamed the field names to comply with the usual django naming convention (school instead of school_id for the foreign key)

Now you can delete StudentDailyTrans and StudentCrossMap we are saving the same data more efficiently and yet without redundancy. And that eliminates the problem you asked about!!

You will agree with me that the code is a lot more readable.

๐Ÿ‘คe4c5

Leave a comment