ContentType Compliance Request Does Not Exist

So, I recently tried to load some fixtures configured by a friend into my database. When I start the server and load various pages, although I get an error:

Caught DoesNotExist while rendering: ContentType matching query does not exist. 

I tried to run syncdb and even reset each of the applications individually, but they were out of luck. Any ideas on how to make this mistake go away?

+6
source share
5 answers

If you look inside the device, each device has three root fields: PK, fields (which is a set of fields for writing PK'th in this table) and model , which contains appname.modelname, from which ORM displays information about the table.

This is the name appname.modelname that Django looks through the ContentType engine to find out which table to put your data in.

Your friend has provided you with at least one device in which the contents of the model field do not match any real model in your database. This may be a wrong letter, a misunderstanding, a change in the name of a model or application, or any number of errors. But the device does not correspond to any model in your project, and the importer of the device tells you this, stating that it cannot correspond to the model name indicated with any names in the ContentType table of the projects.

The correction can be as simple as finding out what the table should have as ContentType, then open the device and perform a bulk search and replace in the model: line.

EDIT:

This is a long (long!) Expired edit. If you are going to dumpdata , which contains shared data or links to shared tables elsewhere, you should (I really can't stress how much you should) recognize the dumpdata --natural flag. Instead of storing contentType information by number, it will save it by name, making reloading the database far, much easier and less error prone.

+11
source

You can manually check each ContentType table in your db or:

  • If your tables are empty, deletes the tables of your models in your db et re-run syncdb (only if your in development)

Or you can use one of the Django migration tools:

+1
source

I found another reason for this error, I wanted to add if this helps someone else. What caused this problem for me was that I created a group with specific permissions and then uninstalled the application that was indicated in the group.

In particular, I installed the reversion at some point and created a group called "Site Editor", which gave the user the right to create, edit and delete changes. Later, I did not install the revision, but the group permissions remained when I ran the "dumpdata" command:

 [ { "fields": { "name": "Site Editor", "permissions": [ [ "add_logentry", "admin", "logentry" ], [ "change_logentry", "admin", "logentry" ], [ "delete_logentry", "admin", "logentry" ], [ "add_group", "auth", "group" ], [ "change_group", "auth", "group" ], [ "delete_group", "auth", "group" ], [ "add_revision", "reversion", "revision" ], [ "change_revision", "reversion", "revision" ], [ "delete_revision", "reversion", "revision" ], [ "add_version", "reversion", "version" ], [ "change_version", "reversion", "version" ], [ "delete_version", "reversion", "version" ], [ "add_session", "sessions", "session" ], [ "change_session", "sessions", "session" ], [ "delete_session", "sessions", "session" ], [ "add_site", "sites", "site" ], [ "change_site", "sites", "site" ], [ "delete_site", "sites", "site" ] ] }, "model": "auth.group", "pk": 2 }] 

When I tried to run the "loaddata" command, I ran into this error all the time:

 django.core.serializers.base.DeserializationError: Problem installing fixture '/Users/me/Documents/Sites/project/path/fixtures/configuration.json': ContentType matching query does not exist. 

My solution was to simply remove any link to the reverse and versions in the device itself, for example:

  [ { "fields": { "name": "Site Editor", "permissions": [ [ "add_logentry", "admin", "logentry" ], [ "change_logentry", "admin", "logentry" ], [ "delete_logentry", "admin", "logentry" ], [ "add_group", "auth", "group" ], [ "change_group", "auth", "group" ], [ "delete_group", "auth", "group" ], [ "add_session", "sessions", "session" ], [ "change_session", "sessions", "session" ], [ "delete_session", "sessions", "session" ], [ "add_site", "sites", "site" ], [ "change_site", "sites", "site" ], [ "delete_site", "sites", "site" ] ] }, "model": "auth.group", "pk": 2 }] 

Then I managed to import the device without any problems.

0
source

From django 1.7, dumpdata options have changed: see http://polarhome.com:753/doc/python-django-doc/html/topics/serialization.html

So you use:

 python manage.py dumpdata --natural-foreign --natural-primary --exclude > my_fixture.json python manage.py loaddata my_fixture.json 

Alternatively, you can also solve the root cause: make sure the content types match the source and destination databases. I ran into the same error moving data between databases, where db1 still had content types from applications that were removed on average. Importing data into db2 where applications have never been present results in this error message.

In this case, edit the database level -t, the django_content_type table in db1, and delete the content types that are no longer used in the django application. Then reconfigure or copy the data to db2 again.

If the content types are listed in other tables, you may need to delete them first or use the DROP CASCADE command (risky!).

WARNING: Editing at the database level is a risky business, so be sure to make a backup before starting work and do not do this in production databases.

Depending on the type of database, you will need another editing tool.

 mysql -> [MySQLWorkBench][1] postgres -> [pgAdmin][2] SQLite -> [SQLite Browser][3] 
0
source

In some cases, this error occurs when your device contains links to a model that does not exist, either because it was not installed, or its application was not added by your INSTALLED_APPS. Unfortunately, the Django error message is pretty useless when tracking this.

If you edit the Queryset.get method in django/db/models/query.py to print the passed *args and **kwargs , you will get a more useful error message, for example:

 DeserializationError: Problem installing fixture ... ContentType matching query does not exist. args=() kwargs={'model': u'somenewmodel', 'app_label': u'somenewapp'} 

You can then verify that this model / application is installed or removes these entries from your device.

0
source

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


All Articles