I recently switched from Django 1.6 to 1.7, and I began using migrations (I never used South).
在1.7之前,我用fixture/initial_data.json
文件加载初始数据,该文件是用python manage.py syncdb
命令加载的(在创建数据库时).
现在,我开始使用迁移,此行为已弃用:
If an application uses migrations, there is no automatic loading of fixtures. Since migrations will be required for applications in Django 2.0, this behavior is considered deprecated. If you want to load initial data for an app, consider doing it in a data migration. (https://docs.djangoproject.com/en/1.7/howto/initial-data/#automatically-loading-initial-data-fixtures)
The official documentation does not have a clear example on how to do it, so my question is :
使用数据迁移导入此类初始数据的最佳方式是什么:
- Write Python code with multiple calls to
mymodel.create(...)
, - Use or write a Django function (like calling
loaddata
) to load data from a JSON fixture file.
我更喜欢第二种 Select .
I don't want to use South, as Django seems to be able to do it natively now.