I'm following the instructions here to create my first Django fixture. I've created a JSON file. But there is a complication: The model I'm trying to populate inherits from MPTTModel
Here is what my Django JSON fixture file initial_data.json
looks like:
[
{
"model": "MyApp.MyModel",
"pk": 1,
"fields": {
"level": 0,
"parent": null,
"name": "My String"
}
}
]
When I run this fixture, I get the error shown below. It turns out there are a handful of other fields that must be defined in the fixture for this model: rght
, lft
, tree_id
, level
.
django.db.utils.IntegrityError: Problem installing fixture
'MyApp/fixtures/initial_data.json': Could not load MyApp.MyModel(pk=1):
null value in column "lft" violates not-null constraint
Failing row contains (1, My String, null, , null, null, null, 0).
I can figure out what the level
attribute is supposed to be and insert it into the fixture file. But how am I supposed to figure out and set the values of rght
, lft
, tree_id
in the this fixture?