django - 加载夹具时 FieldDoesNotExist

标签 django django-fixtures

我正在尝试加载一个名为initial_data.json的装置:

[{"pk": 1, "model": "contenttypes.contenttype", "fields": {"model": "logentry", "name": "log entry", "app_label": "admin"}}, {"pk": 2, "model": "contenttypes.contenttype", "fields": {"model": "permission", "name": "permission", "app_label": "auth"}}, {"pk": 3, "model": "contenttypes.contenttype", "fields": {"model": "group", "name": "group", "app_label": "auth"}}, {"pk": 4, "model": "contenttypes.contenttype", "fields": {"model": "user", "name": "user", "app_label": "auth"}}, {"pk": 5, "model": "contenttypes.contenttype", "fields": {"model": "contenttype", "name": "content type", "app_label": "contenttypes"}}, {"pk": 6, "model": "contenttypes.contenttype", "fields": {"model": "session", "name": "session", "app_label": "sessions"}}, {"pk": 7, "model": "contenttypes.contenttype", "fields": {"model": "tweet", "name": "tweet", "app_label": "tweeter"}}, {"pk": "2pwa7lb5legwb02jw2h76f1e70j2jmo7", "model": "sessions.session", "fields": {"expire_date": "2014-09-14T00:20:41.773Z", "session_data": "OWQ4MmE3ZGRkZjliOWY3OTQ5OTdiMDIyYjE5ZWMwNmUwZTAyMThhMjp7Il9hdXRoX3VzZXJfYmFja2VuZCI6ImRqYW5nby5jb250cmliLmF1dGguYmFja2VuZHMuTW9kZWxCYWNrZW5kIiwiX2F1dGhfdXNlcl9pZCI6MX0="}}, {"pk": "ncl522f8kc6bf242chahmc2squtioirb", "model": "sessions.session", "fields": {"expire_date": "2014-09-14T01:19:42.407Z", "session_data": "NjY0NjliYjNkNDk0ODJhYWRjMDk5MjNjODA1NTAxYWIzZjg3ZGFkYzp7fQ=="}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 1}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 1}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 2}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 2}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 2}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 3}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 3}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 4}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 5}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 6}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_tweet", "name": "Can add tweet", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_tweet", "name": "Can change tweet", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_tweet", "name": "Can delete tweet", "content_type": 7}}, {"pk": 1, "model": "auth.user", "fields": {"username": "nina", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2014-08-31T00:20:41.771Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$2LSBfxYO9fJJ$UT/BLyRLwBQIOUtOfA2aKkGw+xe44ZNYD2TWXqXoT3E=", "email": "", "date_joined": "2014-08-30T18:10:53.539Z"}}, {"pk": 2, "model": "auth.user", "fields": {"username": "admin", "first_name": "Admin", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2014-08-31T00:22:38Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$6JY3bvlplRf0$Rm6rcK9M3LNuTw1uZ3B/Je7rq420UCaf2iwmY8pIv2U=", "email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e8898c858186a8898c858186c68b8785" rel="noreferrer noopener nofollow">[email protected]</a>", "date_joined": "2014-08-31T00:22:38Z"}}, {"pk": 3, "model": "auth.user", "fields": {"username": "bob", "first_name": "Bob", "last_name": "Bobman", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "2014-08-31T00:23:06Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$ehuPT7BoKVpF$VZTxDeaHtLG7jU4wQ1erlFciwMk7l8aCp9MIjSVa/NU=", "email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="43212c2103212c216d202c2e" rel="noreferrer noopener nofollow">[email protected]</a>", "date_joined": "2014-08-31T00:23:06Z"}}, {"pk": 4, "model": "auth.user", "fields": {"username": "amy", "first_name": "Amy", "last_name": "Smith", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "2014-08-31T00:23:24Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$Tv4vWeWICkfS$qcMP+xddceQZMVjHbdOhOsV6LKOQntKOkiaqdEzS2p8=", "email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9a8a4b089baa4a0bda1e7aaa6a4" rel="noreferrer noopener nofollow">[email protected]</a>", "date_joined": "2014-08-31T00:23:24Z"}}, {"pk": 1, "model": "tweeter.tweet", "fields": {"text": "I'm an Admin! ", "user": 2, "timestamp": "2014-08-30T18:51:04Z"}}, {"pk": 2, "model": "tweeter.tweet", "fields": {"text": "Bob is the coolest name EVAR", "user": 3, "timestamp": "2014-08-29T18:51:19Z"}}, {"pk": 3, "model": "tweeter.tweet", "fields": {"text": "I <3 Tweeter", "user": 4, "timestamp": "2014-08-30T15:52:09Z"}}, {"pk": 1, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-08-31T00:22:38.417Z", "object_repr": "Admin", "object_id": "2", "change_message": "", "user": 1, "content_type": 4}}, {"pk": 2, "model": "admin.logentry", "fields": {"action_flag": 2, "action_time": "2014-08-31T00:22:57.048Z", "object_repr": "Admin", "object_id": "2", "change_message": "Changed first_name, email, is_staff and is_superuser.", "user": 1, "content_type": 4}}, {"pk": 3, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-08-31T00:23:06.858Z", "object_repr": "Bob", "object_id": "3", "change_message": "", "user": 1, "content_type": 4}}, {"pk": 4, "model": "admin.logentry", "fields": {"action_flag": 2, "action_time": "2014-08-31T00:23:17.098Z", "object_repr": "Bob", "object_id": "3", "change_message": "Changed first_name, last_name and email.", "user": 1, "content_type": 4}}, {"pk": 5, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-08-31T00:23:24.481Z", "object_repr": "Amy", "object_id": "4", "change_message": "", "user": 1, "content_type": 4}}, {"pk": 6, "model": "admin.logentry", "fields": {"action_flag": 2, "action_time": "2014-08-31T00:23:35.860Z", "object_repr": "Amy", "object_id": "4", "change_message": "Changed first_name, last_name and email.", "user": 1, "content_type": 4}}, {"pk": 7, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-08-31T00:51:05.451Z", "object_repr": "I'm an Admin! ", "object_id": "1", "change_message": "", "user": 1, "content_type": 7}}, {"pk": 8, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-08-31T00:51:26.097Z", "object_repr": "Bob is the coolest name EVAR", "object_id": "2", "change_message": "", "user": 1, "content_type": 7}}, {"pk": 9, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-08-31T00:52:12.916Z", "object_repr": "I <3 Tweeter", "object_id": "3", "change_message": "", "user": 1, "content_type": 7}}, {"pk": 10, "model": "admin.logentry", "fields": {"action_flag": 2, "action_time": "2014-08-31T01:06:18.846Z", "object_repr": "admin", "object_id": "2", "change_message": "Changed username.", "user": 1, "content_type": 4}}, {"pk": 11, "model": "admin.logentry", "fields": {"action_flag": 2, "action_time": "2014-08-31T01:06:26.076Z", "object_repr": "bob", "object_id": "3", "change_message": "Changed username.", "user": 1, "content_type": 4}}, {"pk": 12, "model": "admin.logentry", "fields": {"action_flag": 2, "action_time": "2014-08-31T01:06:34.096Z", "object_repr": "amy", "object_id": "4", "change_message": "Changed username.", "user": 1, "content_type": 4}}]

但是当我运行 syncdb 或使用 load data 时,出现以下错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
    call_command("migrate", **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 364, in sync_apps
    hide_empty=True,
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 60, in handle
    self.loaddata(fixture_labels)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 90, in loaddata
    self.load_label(fixture_label)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 141, in load_label
    for obj in objects:
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/serializers/json.py", line 84, in Deserializer
    six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/serializers/json.py", line 78, in Deserializer
    for obj in PythonDeserializer(objects, **options):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/serializers/python.py", line 120, in Deserializer
    field = Model._meta.get_field(field_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/options.py", line 554, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.serializers.base.DeserializationError: Problem installing fixture '/Users/wrb473/Documents/workspace/angulardjango/tweeter/fixtures/initial_data.json': ContentType has no field named u'name'

治具问题出在哪里?

最佳答案

在此页面上:https://docs.djangoproject.com/en/1.8/ref/contrib/contenttypes/#django.contrib.contenttypes.models.ContentType

“Django 1.8 中的更改: 在 Django 1.8 之前, name 属性是 ContentType 模型上的一个真实字段。” -- 意味着从 1.8 开始它不是一个真实字段。你使用的是 1.8 吗?如果你从 ContentType 固定装置中删除 name ,它会起作用吗?

关于django - 加载夹具时 FieldDoesNotExist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32725522/

相关文章:

python - 如何为没有字段的模型制作 Django 固定装置?

python - 跟踪 celery.group 任务的进度?

django - 运行PyCharm测试时,如何解决“django.core.exceptions.ImproperlyConfigured:找不到GDAL库”?

Django - XML 中的夹具

django - 将信息从 Scrapy 爬虫持续导出到 Django 应用程序数据库的最佳方法是什么?

python - 如何在 Django 1.6 模型装置中使用某些字段而不是主键?

django - 如何迁移django自定义base64字段。栏位不存在

python - 分配选项以在显示时选择下拉列表

django-allauth Facebook 和 Google 社交网络登录失败

Django 测试和 ContentType 通用关系装置