Django Deserialization Error Problem installing Fixture

2024/10/18 12:19:41
Traceback (most recent call last):File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/serializers/json.py", line 69, in Deserializeryield from PythonDeserializer(objects, **options)File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/serializers/python.py", line 91, in DeserializerModel = _get_model(d["model"])
KeyError: 'model'The above exception was the direct cause of the following exception:Traceback (most recent call last):File "manage.py", line 15, in <module>execute_from_command_line(sys.argv)File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_lineutility.execute()File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in executeself.fetch_command(subcommand).run_from_argv(self.argv)File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argvself.execute(*args, **cmd_options)File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in executeoutput = self.handle(*args, **options)File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 72, in handleself.loaddata(fixture_labels)File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 113, in loaddataself.load_label(fixture_label)File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 168, in load_labelfor obj in objects:File "/Users/sparshkedia/Desktop/task/venv/lib/python3.6/site-packages/django/core/serializers/json.py", line 73, in Deserializerraise DeserializationError() from exc
django.core.serializers.base.DeserializationError: Problem installing fixture '/Users/sparshkedia/Desktop/task/movie_rs/movies.json'

This is the above error showing when I am trying to deserialize my json file into the database.

My json file looks like this:

[{"description": "A cowboy doll is profoundly threatened and jealous when a new spaceman figure supplants him as top toy in a boy's room.","genre": "Animation,Adventure,Comedy,Family,Fantasy","imdb_url": "https://www.imdb.com/title/tt0114709/","img_url": "https://m.media-amazon.com/images/M/MV5BMDU2ZWJlMjktMTRhMy00ZTA5LWEzNDgtYmNmZTEwZTViZWJkXkEyXkFqcGdeQXVyNDQ2OTk4MzI@._V1_UX182_CR0,0,182,268_AL__QL50.jpg","movie_id": 114709,"title": "Toy Story","users_rating": 8.3,"year": 1995},{"description": "George Banks must deal not only with the pregnancy of his daughter, but also with the unexpected pregnancy of his wife.","genre": "Comedy,Family,Romance","imdb_url": "https://www.imdb.com/title/tt0113041/","img_url": "https://m.media-amazon.com/images/M/MV5BOTEyNzg5NjYtNDU4OS00MWYxLWJhMTItYWU4NTkyNDBmM2Y0XkEyXkFqcGdeQXVyMTQxNzMzNDI@._V1_UX182_CR0,0,182,268_AL__QL50.jpg","movie_id": 113041,"title": "Father of the Bride Part II","users_rating": 6,"year": 1995}]

What do i need to do to feed the json file into the database? I have also created appropriate movies model which contains all the fields as per the json file.

I am using python manage.py loaddata movies.json for this. Is there any other approach, if yes please help me with it?

Answer

Fixtures files must match django serialization format, e.g:

[{"pk": "4b678b301dfd8a4e0dad910de3ae245b","model": "sessions.session","fields": {"expire_date": "2013-01-16T08:16:59.844Z",...}}
]

So you need to rewrite your fixtures in the following way:

  1. Add model key
  2. Add pk field
  3. Move the rest of fields to fields inner object
https://en.xdnf.cn/q/72962.html

Related Q&A

Python HTTP Exception Handling

Im running a program that downloads files from a web sit. Ive introduced one exception handling urllib.error.HTTPError, but now Im getting from time to time additional errors that Im not sure how to ca…

Weird lambda behaviour in loops [duplicate]

This question already has answers here:What do lambda function closures capture?(8 answers)Closed 10 years ago.I stumbled upon a behaviour in python that I have a hard time understanding. This is the…

Why does inspect return different line for class inheriting from superclass?

While trying to figure out if a function is called with the @decorator syntax, we realized that inspect has a different behaviour when looking at a decorated class that inherits from a superclass.The f…

Sorting a list of tuples with multiple conditions

I am currently trying to sort the following list:list_ = [(1, 0101), (1, 1010), (1, 101), (2, 01), (2, 010), (2, 10)]These are the steps I want to take in order to sort it:Sort the list by the value of…

Tensorboard error: Tensor object has no attribute value

My goal: Add arbitrary text to tensorboard.My code:text = "muh teeeext" summary = tf.summary.text("Muh taaaag", tf.convert_to_tensor(text)) writer.add_summary(summary)My error:File …

How to embed Google Speech to Text API in Python program? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

shell script remote execution using python

Is there a way that I can use Python on Windows to execute shell scripts which are located on a remote Unix machine?P.S: Sorry about the late edit. I do know of Paramiko, but I wanted to know if there…

Shutdown for socketserver based Python 3 server hangs

I am working on a "simple" server using a threaded SocketServer in Python 3.I am going through a lot of trouble implementing shutdown for this. The code below I found on the internet and shut…

How do I url encode in Python?

I tried this: but it doesnt work.print urllib.urlencode("http://"+SITE_DOMAIN+"/go/")I want to turn it into a string with url encodings

resampling pandas series with numeric index

suppose I have a pandas.Series with index with numeric value type e.g. pd.Series( [10,20], [1.1, 2.3] )How do we resample above series with 0.1 interval? look like the .resample func only work on date…