0

我尝试按照djangoproject中的建议加载初始数据。但我无法在我的数据库上加载对象。但是当我尝试加载数据时,它总是说

> python manage.py loaddata ./fixtures/initial_data.json
Installed 0 object(s) from 0 fixture(s)

但我有关于 initial_data.json [/test-project/tableTest/tableTest/fixtures/initial_data.json] 的数据

[
    {
        "model":"tableTest.person",
        "pk":1,
        "fields": {
            "name":"Kevin"
        }
    },
    {
        "model":"tableTest.person",
        "pk":2,
        "fields": {
            "name":"Harry"
        }
    },
    {
        "model":"tableTest.person",
        "pk":3,
        "fields": {
            "name":"Piter"
        }
    }
]

#models.py
from django.db import models


class Person(models.Model):
    name = models.CharField(max_length=100, verbose_name="full name")

我也试过./manage.py loaddata pwd/tableTest/fixtures/initial_data.json但未能成功。请帮我建议我错过了什么。

4

1 回答 1

1

出现此问题是因为我在项目目录而不是 app 目录中编写模型的定义,并且我在模型上定义的表不是在运行时创建的syncdb。后来我创建了一个应用程序并将fixtures,models.py,views.py移动到应用程序目录,重写urls.py。然后数据加载成功。

于 2014-06-27T06:05:49.120 回答