How to move a model between two Django apps (Django 1.7)

后端 未结 11 1689
日久生厌
日久生厌 2020-11-28 17:35

So about a year ago I started a project and like all new developers I didn\'t really focus too much on the structure, however now I am further along with Django it has start

11条回答
  •  时光说笑
    2020-11-28 18:15

    You can try the following (untested):

    1. move the model from src_app to dest_app
    2. migrate dest_app; make sure the schema migration depends on the latest src_app migration (https://docs.djangoproject.com/en/dev/topics/migrations/#migration-files)
    3. add a data migration to dest_app, that copies all data from src_app
    4. migrate src_app; make sure the schema migration depends on the latest (data) migration of dest_app -- that is: the migration of step 3

    Note that you will be copying the whole table, instead of moving it, but that way both apps don't have to touch a table that belongs to the other app, which I think is more important.

提交回复
热议问题