views:

261

answers:

1

I'm creating my own Group model; I'm not referring to the builtin Group model. I want each hroup to be a member of another group (it's parent), but there is the one "top" group that doesn't have a parent group.

The admin interface won't let me create a group without entering a parent. I get the error personnel_group.parent_id may not be NULL. My Group model looks like this:

class Group(models.Model):
    name = models.CharField(max_length=50)
    parent = models.ForeignKey('self', blank=True, null=True)
    order = models.IntegerField()
    icon = models.ImageField(upload_to='groups', blank=True, null=True)
    description = models.TextField(blank=True, null=True)

How can I accomplish this?

Thanks.

+2  A: 

I created the database before I added blank=True, null=True to the parent field definition. syncdb can't deal with that type of change, so Django wasn't picking up on my changes.

I deleted my database and let syncdb create another and it worked fine.

Greg
You should consider using a database scheme migration tool like South.
Török Gábor
is there maybe a better way to do this instead of deleting the whole db?
niklasfi