# ForeignKey on\_delete

**URL:** <https://forum.djangoproject.com/t/foreignkey-on-delete/19438>\
**Category:** Using the ORM\
**Created:** [March 11, 2023, 7:05pm UTC](https://forum.djangoproject.com/t/foreignkey-on-delete/19438 "2023-03-11T19:05:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![silviogesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/silviogesell/32/10974_2.png) [@silviogesell](https://forum.djangoproject.com/u/silviogesell)\
**Post date:** [March 11, 2023, 7:05pm UTC](https://forum.djangoproject.com/t/foreignkey-on-delete/19438/1 "2023-03-11T19:05:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 11, 2023, 7:51pm UTC](https://forum.djangoproject.com/t/foreignkey-on-delete/19438/2 "2023-03-11T19:51:38Z")

</div>

Because that’s the documented behavior of the `on_delete` attribute of a ForeignKey field. See [Model field reference | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.ForeignKey.on_delete)
