Django does not honor ON DELETE CASCADE
This is my model:
class Subscriber(models.Model):
...
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, null=True)
...
This is the generated SQL, according to sqlmigrate (and to manual inspection of the database):
ALTER TABLE `myapp_subscriber` ADD CONSTRAINT `myapp_subscriber_tenant_id_b52815ee_fk_myapp_tenant_id` FOREIGN KEY (`tenant_id`) REFERENCES `myapp_tenant` (`id`);
I was expecting something like this:
CREATE TABLE child (
id INT,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id)
REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;
With the ON DELETE CASCADE.
MySql (MariaDB actually) complains when I delete:
SQL Error (1451): Cannot delete or update a parent row: a foreign key constraint fails
Which makes sense since there is no ON DELETE CASCADE clause.
Why is Django 2.1.5 not honoring the ON DELETE CASCADE clause?