ForeignKey on_delete

Hi Team,

I created a table with a foreign key and an on_delete property. But in my database (MariaDB) “ON DELETE CASCADE” does not appear. Why?

class Visitors(models.Model):
name = models.CharField(max_length=50, null=False, blank=False)

class Meta:
    db_table = "visitors"

class VisitedPages(models.Model):
visitor1 = models.ForeignKey(to=Visitors, on_delete=models.CASCADE, blank=False, null=False)
# visitor2 = models.ForeignKey(to=Visitors, on_delete=models.RESTRICT, blank=False, null=False)
# visitor3 = models.ForeignKey(to=Visitors, on_delete=models.SET_NULL, blank=True, null=True)

class Meta:
    db_table = "pages"

show create table pages;

CREATE TABLE pages (
id bigint(20) NOT NULL AUTO_INCREMENT,
visitor1_id bigint(20) DEFAULT NULL,
PRIMARY KEY (id),
KEY pages_visitor1_id_1a5cd9d1_fk_visitors_id (visitor1_id),
CONSTRAINT pages_visitor1_id_1a5cd9d1_fk_visitors_id FOREIGN KEY (visitor1_id) REFERENCES visitors (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

Because that’s the documented behavior of the on_delete attribute of a ForeignKey field. See Model field reference | Django documentation | Django