1👍
Django will make migrations if you change the choices=…
parameter [Django-doc], in fact Django will make a migration if you change any parameter. But the default migration handler… will not do anything when you change the choices
. One can implement a different handler, but likely it is not worth the effort.
This thus means that eventually no database changes will be done, so we will have to do this ourselves. If you want to modify data, you can make a data migration [Django-doc]. A data migration is just like a normal migration, except that we write how the database should change.
We make a data migration with:
python manage.py makemigrations --empty app_name
In the migration file, we can then construct an update query:
from django.db import migrations
def red_to_blue(apps, schema_editor):
Car = apps.get_model('app_name', 'Car')
Car.objects.filter(color='Red').update(color='Blue')
class Migration(migrations.Migration):
dependencies = [
("app_name", "1234_some_migration"),
]
operations = [
migrations.RunPython(red_to_blue),
]
If we then migrate, it will run the red_to_blue
function, and migrate the data in the database.