简体   繁体   English

在生产环境中将字段添加到现有django应用

[英]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
  • added 'south' to INSTALLED_APPS 已将“南”添加到INSTALLED_APPS
  • 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: 现在,我进行了以下迁移:

  • 0001_initial.py 0001_initial.py
  • 0002_auto__add_field_myapp_fieldname.py 0002_auto__add_field_myapp_fieldname.py

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.

相关问题 Django将字段添加到现有模型应用程序 - Django add field to existing model app 将不存在的字段名称添加到 django 查询 - add non existing field name to django query 如何将现有的Django应用程序/项目部署/迁移到Heroku上的生产服务器? - How to deploy / migrate an existing django app / project to a production server on Heroku? Django:生产环境中的编码问题 - Django: Encoding problem on production environment Django - 生产环境中 FileSystemStorage 的替代方案 - Django - Alternative for FileSystemStorage in Production Environment 尝试将新的 model 和字段添加到 Django 中的现有数据中 - Trying to add new model and field to existing data in Django 将新的唯一字段添加到现有Django模型时的最佳实践 - Best practice when add a new unique field to an existing django model Django 在管理 model 时尝试添加现有字段 - Django trying to add an existing field when making a model managed 我的django应用程序中的环境设置设置为debug false,但在生产中它的行为就像是true - environment settings in my django app are set to debug false but in production it acts as if its true 将Django应用程序部署到生产服务器时,我应该在git clone中包括环境(env)吗? - Deploying django app to production server, should I include environment (env) in git clone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM