I have a model with several bool fields. I'd like to replace them with a single int field where each bit represents one of the old bools. I've added the new int field and run makemigrations. Is there a way I can modify the migrations file and define how I'd like the new int fields' values to be defined? Like I said, I would like them to take the values of the previous bool fields.
CodePudding user response:
Data migration is what you need.
- Add new field to the model, apply
makemigrations. - Create a data migration, which would transfer data from old fields to the new one and run it.
- Remove old fields.
Data migration could be created with:
python manage.py makemigrations --empty yourappname
And inside it you should use RunPython or RunSQL depending on what exactly do you need.
