我正在使用./manage.py loaddata file.json
加载一个用./manage.py dumpdata > ../directory/file.json
创建的JSON文件,我得到了以下错误:
matching_chars: 6
Traceback (most recent call last):
File "/opt/venv/djangoEnv/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 "/opt/venv/djangoEnv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/venv/djangoEnv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/venv/djangoEnv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/venv/djangoEnv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/venv/djangoEnv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
self.loaddata(fixture_labels)
File "/opt/venv/djangoEnv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 123, in loaddata
self.load_label(fixture_label)
File "/opt/venv/djangoEnv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 181, in load_label
for obj in objects:
File "/opt/venv/djangoEnv/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/example/rep/file.json':
字符串
我不明白为什么会有错误-如果文件是由同一个程序创建和读取的(manage.py
),为什么它不工作?
1条答案
按热度按时间dddzy1tm1#
**[update]**运行
./manage.py dumpdata --skip-checks > file.json
也解决了这个问题。感谢this Reddit post找到了答案。
通过使用
./manage.py dumpdata --output ../directory/file.json
,我得到了一个JSON文件,可以导入没有任何错误。然后我使用vim diff来找出工作文件(
--output
)和损坏文件(>
)之间的区别。在破碎的JSON文件的顶部,第一行是:
字符串
我不知道为什么使用
dumpdata
与输出重定向会增加这个,但删除它解决了我的问题。具有讽刺意味的是,
matching_chars: 6
实际上是错误消息的第一行--我只是没有理解它。