what does on_delete=models.PROTECT and on_delete=models.CASCADE do on Django models?

  • CASCADE
    Cascade deletes. Django emulates the behavior of the
    SQL constraint ON DELETE CASCADE and also deletes the object
    containing the ForeignKey.

  • PROTECT
    Prevent deletion of the referenced object by raising
    ProtectedError, a subclass of django.db.IntegrityError.

the things get deleted because once you change your model you need to do makemigrations and migrate to see the change.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)