Closed GoogleCodeExporter closed 9 years ago
Looks like this is quite a specific error that I cannot seem to reproduce or
fully understand.
Generally, this attributes need to be present for a complete and efficient tree.
Are you still encountering the error?
Original comment by matjaz.c...@gmail.com
on 4 Sep 2010 at 1:04
I get this error too. It happens when trying to load some data from fixtures
into the tree.
Original comment by Valentin...@gmail.com
on 9 Nov 2010 at 10:11
Valentin
What version of mptt are you using? Can you please supply your models.py and
fixture?
Original comment by craig.ds@gmail.com
on 10 Nov 2010 at 6:38
mptt is installed with easy_install: django_mptt-0.4.2-py2.6.egg
Model:
class Category (MPTTModel):
name = models.CharField(_('name'), max_length = 128)
parent = models.ForeignKey('self', null = True, blank = True)
icon = models.ImageField(_('icon'), upload_to = 'icons', blank = True, null = True)
slug = models.SlugField(_('slug'))
def __unicode__(self):
return self.name
class Meta:
verbose_name = _('category')
verbose_name_plural = _('categories')
Fixture:
- model: my_app.category
pk: 1
fields:
name: Category1
Original comment by Valentin...@gmail.com
on 12 Nov 2010 at 12:33
That fixture certainly looks quite broken - it doesn't have any of the MPTT
fields, or parent, icon or slug. slug is not-null.
If that's really the fixture you've got, I suspect it wasn't generated
properly, unrelated to django-mptt ?
I tried dumping a fixture from that test model, and it ends up like this (as I
expected):
python manage.py dumpdata --format=json testapp
[{"pk": 1, "model": "testapp.category", "fields": {"rght": 2, "name": "foo", "parent": null, "level": 0, "lft": 1, "tree_id": 1, "slug": "", "icon": ""}}]
Original comment by craig.ds@gmail.com
on 12 Nov 2010 at 1:11
Sorry, I've added the slug field later than createed this fixture. But adding
it changes nothing, I get the error
IntegrityError: null value in column "lft" violates not-null constraint
anyway. Parent is not needed here because it is a root node. And writing lft,
level and rght in fixture seems wrong, as they must be calculated
automatically, not by hand.
Original comment by Valentin...@gmail.com
on 12 Nov 2010 at 1:21
You can't load an old fixture with missing fields. So of course you will get
that error, since there is no lft in your fixture.
If you must make fixtures by hand, you'll have to add the MPTT fields as well.
I don't see any sane way around that. Adding null=True to these fields would
just mean possible integrity errors, since it makes no sense to have an MPTT
model with no MPTT values defined.
Of course, the easier and less error prone way to make a fixture would be to
create the data you want on a dev machine, and then dump it using manage.py
dumpdata :)
Original comment by craig.ds@gmail.com
on 12 Nov 2010 at 11:27
I've hit the same problem. It would be good to set a default so that data can
still be imported from old fixtures.
Original comment by i...@madteckhead.com
on 1 Nov 2011 at 4:42
Original issue reported on code.google.com by
calvin.c...@gtempaccount.com
on 13 Sep 2009 at 8:45