I'm trying to figure out how to load test data in Django and Python 3.7. I have the below YAML file
website:
- id: 1
path: "/test"
Pretty basic. In my unit test, I attempt to load it using
management.call_command('loaddata', 'test_data.yaml', verbosity=0)
But this results in the below error. What's wrong with my YAML file that would cause the below error?
======================================================================
ERROR: test_add_articlestat (mainpage.tests.FirstTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/davea/Documents/workspace/mainpage_project/venv/lib/python3.7/site-packages/django/core/serializers/pyyaml.py", line 73, in Deserializer
yield from PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options)
File "/Users/davea/Documents/workspace/mainpage_project/venv/lib/python3.7/site-packages/django/core/serializers/python.py", line 91, in Deserializer
Model = _get_model(d["model"])
TypeError: string indices must be integers
The first line does not look right to me:
website:
The correct format is
-model: appname:modelname
See providing data with fixtures for details
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.