基础不太好额。。
使用的是django,用的自带的ORM。。。
现在有个功能是,评论功能。
评论表comment里有评论内容content和主键ID。
现在想加入一个功能是评论的评论。
目前想到的方案是:
1、增加一个附属评论表暂时取名为comment1,然后增加评论内容content,然后将其设置成外键,关联原来的comment表。
2、是想在原来的表的基础上,增加一个comment_id的字段,让comment_id与comment表中的主键id关联。
现在问题主要是plan2。。。。如果在comment表中添加字段,这个字段该怎么设置,
1、设置成外键ForeignKey?能自己的表的字段当自己的表外键吗?
2、设置成OneToOne?试了下不太好。一个comment_id只能关联一个表id,这样一个评论下就没办法多个评论了。。。
3、设置成ManyToMany?不太明白这个怎么玩啊。。
很小白的问题。望有心人解答下。
Assume it is a Weibo system.
Question 1: Yes, but this is not called a foreign key. Just like the navigation bar, the id is the parent of comment_id.
Your business logic is ultimately just two levels of comments (comments for normal replies, comments for replies to comments)
As for onetoonemanytomany, it’s not that complicated. It’s a relationship between the Weibo table and comments
For business foreign keys, handle these logics in your own code and don’t rely on the foreign keys of the database.
I have never done a similar request, but it feels a bit like a tree structure. You can search for infinite data table design.