Django Postgres DeserializationError:安装固定装置时出现问题

时间:2019-03-16 01:44:57

标签: django database postgresql

我正在尝试将开发数据库固定装置导入生产服务器。已经进行了迁移,我尝试将数据库迁移缩减为仅两个类。这是我收到的命令和错误:

错误

(env) root@django-01:/home/projects/server/mysite# python3 local.py loaddata db.json
Traceback (most recent call last):
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/serializers/json.py", line 68, in Deserializer
    objects = json.loads(stream_or_string)
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 19 column 1 (char 229)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "local.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/management/commands/loaddata.py", line 72, in handle
    self.loaddata(fixture_labels)
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/management/commands/loaddata.py", line 113, in loaddata
    self.load_label(fixture_label)
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/management/commands/loaddata.py", line 168, in load_label
    for obj in objects:
  File "/home/projects/server/env/lib/python3.5/site-packages/django/core/serializers/json.py", line 73, in Deserializer
    raise DeserializationError() from exc
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/projects/server/mysite/db.json': 

db.json

    [

{
    "model": "memberships.benefit",
    "pk": 1,
    "fields": {
        "name": "SSL Certificate"
    }
},
{
    "model": "memberships.benefit",
    "pk": 2,
    "fields": {
        "name": "No cancellation fee"
    }
},


]

1 个答案:

答案 0 :(得分:1)

您需要使用正确的json格式,请从json中删除最后一个(

[
  {
    "model": "memberships.benefit",
    "pk": 1,
    "fields": {
      "name": "SSL Certificate"
    }
  },
  {
    "model": "memberships.benefit",
    "pk": 2,
    "fields": {
      "name": "No cancellation fee"
    }
  }
]

推荐this

希望有帮助