Loading initial data with Django 1.7 and data migrations

前端 未结 7 1968
陌清茗
陌清茗 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:21

    The solutions presented above didn't work for me unfortunately. I found that every time I change my models I have to update my fixtures. Ideally I would instead write data migrations to modify created data and fixture-loaded data similarly.

    To facilitate this I wrote a quick function which will look in the fixtures directory of the current app and load a fixture. Put this function into a migration in the point of the model history that matches the fields in the migration.

提交回复
热议问题