Django migration strategy for renaming a model and relationship fields

后端 未结 12 1599
一个人的身影
一个人的身影 2020-11-28 00:54

I\'m planning to rename several models in an existing Django project where there are many other models that have foreign key relationships to the models I would like to rena

12条回答
  •  日久生厌
    2020-11-28 01:32

    I am using Django version 1.9.4

    I have follow the following steps:-

    I have just rename the model oldName to NewName Run python manage.py makemigrations. It will ask you for Did you rename the appname.oldName model to NewName? [y/N] select Y

    Run python manage.py migrate and it will ask you for

    The following content types are stale and need to be deleted:

    appname | oldName
    appname | NewName
    

    Any objects related to these content types by a foreign key will also be deleted. Are you sure you want to delete these content types? If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: Select No
    

    It rename and migrate all existing data to new named table for me.

提交回复
热议问题