artem
artem

Reputation: 16777

How to prevent deletion of related ForeignKey instances?

I have:

I want to delete Model1 instance, but when I do it, the related Model2 instance is deleted too. How to prevent its deletion?

Upvotes: 1

Views: 385

Answers (1)

Jacek Konieczny
Jacek Konieczny

Reputation: 8604

Clear (set to None) the foreign key field of the Model2 instance or point it to some other Model1 instance, before removing the Model1 instance. Otherwise data consistency would be broken if Model1 instance was removed by the Model2 instance not.

Upvotes: 1

Related Questions