[英]Add field to existing django app in production environment
I have an existing django app and would like to add a field to a model. 我有一个现有的django应用程序,想向模型添加字段。 But because the website is already in production, just deleting the database is not an option any more.
但是由于该网站已经投入生产,因此删除数据库已不再是一种选择。
These are the steps I took: 这些是我采取的步骤:
pip install south
python manage.py syncdb
python manage.py convert_to_south [myapp]
So now I have the initial migration and south will recognize the changes. 因此,现在我有了最初的迁移,南方将认识到这些变化。 Then I added the field to my model and ran:
然后,将字段添加到模型中并运行:
python manage.py schemamigration [myapp] --auto
python manage.py migrate [myapp]
Now I have the following migrations: 现在,我进行了以下迁移:
Which commands should I run on my production server now to migrate? 我现在应该在生产服务器上运行哪些命令以进行迁移? Also should I install south first and then pull the code changes and migrations?
还应该先安装南方软件,然后再进行代码更改和迁移吗?
first is to fake the initial migration: 首先是伪造初始迁移:
python manage.py migrate [yourapp] --fake 0001
then you can apply the migration to the db 然后您可以将迁移应用于数据库
python manage.py migrate [yourapp]
I'm assuming you ran convert_to_south
on development, in which case production still wouldn't be aware of the migrations yet. 我假设您在开发中运行了
convert_to_south
,在这种情况下,生产仍然不会意识到迁移。 convert_to_south
automatically fakes the initial migration for you! convert_to_south
自动为您伪造初始迁移! If you were to just run migrate
on production without faking, it should error. 如果仅在不假装的情况下在生产上运行
migrate
,则应该出错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.