Loading initial data with Django 1.7 and data migrations

前端 未结 7 1944
陌清茗
陌清茗 2020-11-27 09:39

I recently switched from Django 1.6 to 1.7, and I began using migrations (I never used South).

Before 1.7, I used to load initial data with a fixture/initial_d

7条回答
  •  执笔经年
    2020-11-27 10:19

    Inspired by some of the comments (namely n__o's) and the fact that I have a lot of initial_data.* files spread out over multiple apps I decided to create a Django app that would facilitate the creation of these data migrations.

    Using django-migration-fixture you can simply run the following management command and it will search through all your INSTALLED_APPS for initial_data.* files and turn them into data migrations.

    ./manage.py create_initial_data_fixtures
    Migrations for 'eggs':
      0002_auto_20150107_0817.py:
    Migrations for 'sausage':
      Ignoring 'initial_data.yaml' - migration already exists.
    Migrations for 'foo':
      Ignoring 'initial_data.yaml' - not migrated.
    

    See django-migration-fixture for install/usage instructions.

提交回复
热议问题