Use of left_visit as primary key causes foreign key issues

Issue #2 resolved
Lars Yencken
repo owner created an issue

In the following scenario, foreign key constraints are violated and you cannot modify the tree:



class Category(HierarchicalModel): name = models.CharField(max_length=15)

class Customer(models.Model): category = models.ForeignKey(Category) name = models.CharField(max_length=50) }}}

Say you have a few customers and categories already. Then you try to update the tree with some extra categories. This involves changing the {{{left_visit}}} of a large number of nodes, but {{{left_visit}}} is each node's primary key (since {{{HierarchicalModel}}} defines it this way). Since there are {{{Customer}}} objects referring to these primary keys, constraints fail when they are changed.

We should instead just define {{{left_visit}}} with {{{db_index=True}}}, and let the user pick a separate primary key.

Comments (3)

  1. Log in to comment