Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentType matching query does not exist

I recently attempted to load some fixtures into my database. When I run the server and load various pages though I get the error:

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

I've tried running syncdb, and resetting each of the apps individually, but haven't had any luck. How do I make this error go away?

like image 559
Ceasar Bautista Avatar asked Jul 14 '11 17:07

Ceasar Bautista


1 Answers

If you look inside the fixture, each fixture has three root fields: the PK, the fields (which is a set of fields for the PK'th entry in that table), and a model, which contains the appname.modelname, from which the ORM derives the table information.

It is that appname.modelname that Django looks up, via the ContentType engine, to figure out which table to put your data into.

Your friend has given you at least one fixture in which the content of the model field does not match any actual model in your database. This may be a misspelling, a misunderstanding, a change of model or application name, or any number of faults. But the fixture does not correspond to any model in your project, and the fixture importer is telling you so, by saying it cannot match the model's designated name with any names in the projects ContentType table.

The fix may be as simple as figuring out what the table is supposed to have as a ContentType, then opening up the fixture and doing a mass search-and-replace on the model: line.

EDIT:

This is a long (long!) overdue edit. If you're about to dumpdata that contains generic data or references to generic tables elsewhere, you must (I really can't emphasize how much you must) learn the dumpdata --natural flag. Rather than save contentType information by number, it will save it by name, making reloading the database far, far easier and less error-prone.

like image 161
Elf Sternberg Avatar answered Oct 24 '22 17:10

Elf Sternberg