ManyToManyField error when having recursive structure. How to solve it?
- by luc
Hello,
I have the following table in the model with a recursive structure (a page can have children pages)
class DynamicPage(models.Model):
name = models.CharField("Titre",max_length=200)
parent = models.ForeignKey('self',null=True,blank=True)
I want to create another table with manytomany relation with this one:
class UserMessage(models.Model):
name = models.CharField("Nom", max_length=100)
page = models.ManyToManyField(DynamicPage)
The generated SQL creates the following constraint:
ALTER TABLE `website_dynamicpage` ADD CONSTRAINT `parent_id_refs_id_29c58e1b` FOREIGN KEY (`parent_id`) REFERENCES `website_dynamicpage` (`id`);
I would like to have the ManyToMany with the page itself (the id) and not with the parent field.
How to modify the model to make the constraint using the id and not the parent?
Thanks in advance