Last active
December 16, 2024 14:35
-
-
Save mintyPT/49f9a3d0fe1ab1f32b219ee41c96c79c to your computer and use it in GitHub Desktop.
Migrate charfield's choice in django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you change some field's choice, django will not migrate the value at | |
# the database level. You need to do it. | |
# | |
# Generate an empty migration: | |
# > python manage.py makemigrations --empty <app_name> | |
# | |
# This will migration the value in the `state` field from `new` to `new_b` | |
# (and back if necessary). | |
from django.db import migrations | |
class Migration(migrations.Migration): | |
dependencies = [("<app_name>", "0001_abc")] | |
operations = [ | |
migrations.RunSQL( | |
"update <app_name>_<table> set state='new_b' where state='new';", | |
"update <app_name>_<table> set state='new' where state='new_b';", | |
) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment