I have these models. The problem is that when I delete a dog record using Django Admin the associated collar record is not being deleted.
I’m on Django 1.2. I thought cascade delete was the default. It it an issue with Collar being linked to a legacy table?
Much thanks in advance.
class Collar(models.Model):
serial_number = models.AutoField(primary_key=True, db_column='serial_number')
weight = models.CharField(max_length=10)
class Meta:
db_table = u'existing_table_from_before_django_was_born'
class Dog(models.Model):
size = models.CharField(max_length=10)
collar = models.OneToOneField(Collar,blank=True, null=True, editable=False)
It is not an issue of the connection to a legacy table. The cascade deletion will work of you delete the Collar object, then the related Dog object will be deleted (probably if you remove blank=True, null=True).
To delete Collar after deletion of Dog you need to overload the delete method of Dog.