Renaming an app with Django and South

前端 未结 6 789
栀梦
栀梦 2020-12-13 02:28

I am renaming an application to a more suitable name. In doing so, I want to ensure that South properly migrates the database (renames database tables and changes reference

6条回答
  •  孤街浪徒
    2020-12-13 02:51

    Disclaimer: This answer is for those who do not care about migration history and have already messed up by renaming the app, completely forgetting about migrations (like I did). Worked for me.

    After changing folder name, dealing with all imports in your code and changing corresponding app name in settings.INSTALLED_APPS, just delete all previous migrations folder. Then make an initial one like this

    manage.py schemamigration new_app --initial
    

    Then, when applying it, fake it like this

    manage.py migrate new_app 0001 --fake
    

    Do not forget to --fake it, otherwise you might end up losing data

    All further migrations will work just fine

    manage.py migrate new_app 0002
    

    Also you can delete from south_migrationhistory where app_name = "old_app"

提交回复
热议问题