I have:
- Model1
- Model2 with field ForeignKey(Model1)
I want to delete Model1 instance, but when I do it, the related Model2 instance is deleted too. How to prevent its deletion?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.