Migrate ManyToManyField to SortedManyToManyField
masterStandard Django migrations created by makemigrations will not correctly handle the transition from ManyToManyField to SortedManyToManyField. To migrate:
- Change the field type in your
models.pytoSortedManyToManyField. - Run
python manage.py makemigrationsto generate a migration file. - Open the generated migration file and locate the
operationslist. - Change
migrations.AlterFieldtosortedm2m.operations.AlterSortedManyToManyField. - Import
AlterSortedManyToManyFieldfromsortedm2m.operationswithin the migration file.
This specialized operation ensures the intermediate table is updated, the ordering field is added, and default values are populated.