Consolidating Django South Migrations

我是研究僧i 提交于 2019-12-06 00:21:01

问题


In the initial stages of my project I'm making a lot of changes to the models and thus I've ended up with a lot of south migrations being generated for my apps. Is it possible to consolidate them in any way before going to my production server to perform the migrations so I don't have like a million migrations for each app? And if so, how would I go about doing that?


回答1:


You could always delete the existing migrations and create a new "initial" migration.

To do this, you will need to:

  1. Remove the migration files for you app (remove the folder altogether)
  2. Run ./manage.py convert_to_south myapp

This will leave you with a single migration corresponding to your app's state current state.


Alternatively, you can always pack your latest migrations together:

  1. Remove the migration files that you want to merge (only if they are the latest onces)
  2. Run ./manage.py schemamigration myapp

This will create a new migration that will correspond to the migrations you removed.


Both of these will likely mess up your development DB.




回答2:


Since this is a development environment, this is how I do it (using SQLite, see below for other SQL servers):

  1. Do all the changes, let the migration files pile up. No committing migration files to VCS
  2. When done, delete all the new migration files
  3. Rename database
  4. Run manage.py migrate. This will create database structure as it was before you made any changes to it.
  5. Run manage.py makemigrations. This will create the necessary migrations that reflect your current state
  6. Move back the original database which already has the final structure & data
  7. Commit migrations files

When using "proper" SQL servers, just keep two databases: production and development. Change project settings to point to production database instead of renaming in step 3. Also, you can skip step 4.



来源:https://stackoverflow.com/questions/14241648/consolidating-django-south-migrations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!