search

Home  >  Q&A  >  body text

mysql - schema database design for Q&A website?

Beginnerdjango, prepare to practice imitating a simplified segfmentfault website. Now I have a few questions.



class Answer(models.Model):

    id = models.IntegerField(primary_key=True)
    user_id = models.PositiveIntegerField(verbose_name='用户ID')
    vote = models.IntegerField(verbose_name='得票')
    data = models.TextField(verbose_name='数据', max_length=4096 * 10)
    post_time = models.DateTimeField(verbose_name='创建时间', default=datetime.datetime.now)
    mod_time = models.DateTimeField(verbose_name='修改时间')

    class Meta:
        verbose_name = '用户回答'


class Question(models.Model):
    Q_CHOICES = (
        ('0', u'Show'),
        ('1', u'Hide'),
        ('2', u'Closed'),
    )

    BOOL_CHOICES = (
        ('0', u'False'),
        ('1', u'True'),
    )

    id = models.IntegerField(primary_key=True)
    name = models.CharField(verbose_name='名称', max_length=128)
    status = models.CharField(verbose_name='状态', max_length=1, choices=Q_CHOICES)
    type = models.SmallIntegerField(verbose_name='类别')
    post_time = models.DateTimeField(verbose_name='创建时间', default=datetime.datetime.now)
    mod_time = models.DateTimeField(verbose_name='修改时间')
    vote = models.IntegerField(verbose_name='得票')
    data = models.TextField(verbose_name='数据', max_length=4096 * 10)
    user_id = models.PositiveIntegerField(verbose_name='用户ID')
    view_num = models.PositiveIntegerField(verbose_name='浏览数')

    class Meta:
        verbose_name = '问题列表'
  1. Now in the database area, the anti-paradigm database design is recommended. Is foreign key suitable for this kind of Q&A website?

  2. What fields are missing from my table? These are the only ones I can think of. Please give me a rough analysis.

Question form

Answer form

Comment form

过去多啦不再A梦过去多啦不再A梦2729 days ago1010

reply all(1)I'll reply

  • 欧阳克

    欧阳克2017-06-30 09:55:50

    In terms of scale, foreign keys are not suitable for large amounts of data, but can be used for small ones; for applications where security and reliability are important, foreign keys should be used, otherwise they may not be used. Detailed analysis of specific situations

    The specific missing fields are determined by the business

    reply
    0
  • Cancelreply