Invalid model identifier for Django fixture data?

I am sure there is a simple answer here, but I do not see this. I am trying to load fixtures into my database, but no matter what model identifier I use, I keep getting the DeserializationError: invalid model identifier:... error.

File structure:

 testproject/ testapp/ fixtures/ data.json __init__.py models.py tests.py views.py sqlite3.db __init__.py manage.py settings.py urls.py 

Since this is my first exit to the fixtures, I use the model from http://www.djangoproject.com/documentation/models/fixtures/ :

 from django.db import models from django.conf import settings class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') pub_date = models.DateTimeField() def __unicode__(self): return self.headline class Meta: ordering = ('-pub_date', 'headline') 

data.json:

 [ { "pk": "3", "model": "testapp.article", "fields": { "headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00" } }, { "pk": "2", "model": "testapp.article", "fields": { "headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00" } }, { "pk": "1", "model": "testapp.article", "fields": { "headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00" } } ] 

I tried testapp.article , testproject.article , testproject.testapp.article and they all throw the same error. I run 1.2.4 with Python 2.6 and use loaddata, not syncdb. Any ideas?

+4
source share
4 answers

Your data.json file is fine, I tried it and it works.

Are you sure your db is in sync with your models?

what do you run to download the file?

as Luke suggested, compare the output of "manage.py dumpdata testapp" with your file

+2
source

I'm not sure if this will help at all, but at the moment I am looking at some devices that I wrote, and all my model identifiers are properly cased.

Here is an example from the settings of my user accounts, but note that this is in YAML.

 - model: auth.User pk: 4 fields: username: avirtue first_name: Aurora last_name: Virtue is_active: true is_superuser: false is_staff: false password: sha1$90431$9347d343e94122f94f9f02988f026a76d339ab02 email: avirtue@someschool.edu - model: users.UserProfile pk: 4 fields: user: 4 school_id: 420985 professor: false 

This is located in the file under the users / fixtures / folder (that is, there are application users, and this file is in this application folder).

As you can see, the models actually come from two different places. The second one I use is the same application and defines UserProfile . The first one is actually from the django.contrib.auth module, which the project uses for authentication.

0
source

I had the same error “Invalid model identifier” several times, and I always realized that it was either using the wrong application name or the application name was spelled incorrectly. This is the "model": "testapp.article", testapp is either spelled incorrectly or expects that the other application name will not be testapp, as in the case above.

0
source

Try checking settings.py, in my case I just forgot to add the application to INSTALLED_APPS

0
source

Source: https://habr.com/ru/post/1333760/


All Articles