在服务器上添加夹具时出现反序列化错误(loaddata)
Posted
技术标签:
【中文标题】在服务器上添加夹具时出现反序列化错误(loaddata)【英文标题】:DeserializationError when adding fixture on server (loaddata) 【发布时间】:2021-05-03 20:23:07 【问题描述】:我正在尝试将我的数据添加到我服务器中的数据库中。我在本地机器上使用完全相同的JSON
文件,它可以工作。但是当我在服务器上做同样的事情时,它给了我Deserialization Error
。
JSON
文件太大,我无法在此处显示,但我确定没有错字。
我完成了所有迁移和数据库工作 - 我可以从管理仪表板添加对象。我该如何解决这个错误?
我得到的错误:
Traceback (most recent call last):
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/serializers/json.py", line 69, in Deserializer
objects = json.loads(stream_or_string)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 72, in handle
self.loaddata(fixture_labels)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 114, in loaddata
self.load_label(fixture_label)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 172, in load_label
for obj in objects:
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/serializers/json.py", line 74, in Deserializer
raise DeserializationError() from exc
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/testuser/myprojectt/myprojectt/articles/fixtures/article.json':
一遍又一遍地检查JSON
,但它仍然在本地工作,但在服务器上出现同样的错误。
【问题讨论】:
查看***.com/questions/16573332/… 【参考方案1】:我在服务器上使用 Ubuntu。并且没有安装git-lfs
。要解决这个问题:
使用sudo apt-get install git-lfs
安装它。
然后在项目目录上运行git lfs pull
。
然后我设法按照自己的意愿处理JSON
数据。
【讨论】:
以上是关于在服务器上添加夹具时出现反序列化错误(loaddata)的主要内容,如果未能解决你的问题,请参考以下文章
在 Django 中为 Selenium 测试加载夹具时出现完整性错误
尝试使用 json.net 和 WCF Rest Service 将 XML 转换为 JSON 输出时出现反斜杠问题