1👍
✅
Couldn’t figure out The Right Way to do it, but managed to hack it by:
- Start with a clean git history (no dirty files) — makes the next steps easier
- Rename the model in question to something else, like Model2
- Run makemigrations
- Revert all changes except the generated migration
- Reorder the generated migration file so
DeleteModel
comes beforeCreateModel
, and change the name of the model being created inCreateModel
back to the original model name. It should look like this:
class Migration(migrations.Migration):
dependencies = [
("<app name>", "<previous migration>"),
]
operations = [
migrations.DeleteModel(
name="ModelName",
),
migrations.CreateModel(
name="ModelName",
fields=[
# < all fields of your model >
],
options={
# < all meta options of your model >
},
),
]
👤vgel
Source:stackexchange.com