Loading initial data with Django 1.7 and data migrations

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

    In order to give your database some initial data, write a data migration. In the data migration, use the RunPython function to load your data.

    Don't write any loaddata command as this way is deprecated.

    Your data migrations will be run only once. The migrations are an ordered sequence of migrations. When the 003_xxxx.py migrations is run, django migrations writes in the database that this app is migrated until this one (003), and will run the following migrations only.

    0 讨论(0)
提交回复
热议问题