ContentType matching query does not exist
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.
I'm surprised no one mentioned the fact that fixture is a list that is being read from first value to last. And it's often possible that there will be a row that mentions a Primary key of a table that will be added latter.
such mistake (generating this extact issue) would look like this in a fixture:
{"model": "lesson", "fields": {"class": 1}},
{
"model": "class",
"pk": 1
}
from above example you can see that <Model> matching query query doesn't exist
(lesson cannot be added because class with pk=1 has not been added yet).
So you have to add classes before you can have lessons, so just switch them up in a fixture.
You can check manually every 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:
the accessible django-evolution
Or the more complex south