Issue
I have model M1. it had a field F1 of type IntegerField. I created a number of items and filled their F1 with numbers.
Then I created new model M2 and changed F1 to be ForeignKey to M2. makemigrations worked fine. But migrate doesn't work - since it can't find M2 items corresponding to old F1 int values. Moreover I can't delete M1 items through shell - attempt to get Objects.all() result in same error.
How can I delete "problematic" items of M1 without flushing database?
Solution
How can I delete "problematic" items of M1 without flushing database?
I would advise to do this as part of the migration, using the RunPython
operation. I.e. you should manually edit the migration that Django generated and insert a RunPython
operation that deletes these "problematic" objects, before F1
changes field type 🙂
Answered By - Dabble Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.