Problem:
Consider a scene where you have a django model with a Foreign Key reference to another Model Instance. Now when you try and update the Foreign Key Instance , one need to remove the already existing instance. While trying to do that django also delete the model instance hosting the Foreign Key reference. So how to delete the Foreign Key Reference object without deleting the host instance.
Solution:
The solution is to update the model with on_delete attribute set as models.SET_NULL. Django by default assumes cascading behavior while deleting any model object.
Not knowing this costed me some precious time to figure this out.
Consider a scene where you have a django model with a Foreign Key reference to another Model Instance. Now when you try and update the Foreign Key Instance , one need to remove the already existing instance. While trying to do that django also delete the model instance hosting the Foreign Key reference. So how to delete the Foreign Key Reference object without deleting the host instance.
Solution:
The solution is to update the model with on_delete attribute set as models.SET_NULL. Django by default assumes cascading behavior while deleting any model object.
Not knowing this costed me some precious time to figure this out.