Django架构师表分区

时间:2016-03-23 03:45:08

标签: mysql django partitioning

我需要对表进行分区。我试图使用建筑师。请在下面找到模型类。

@architect.install('partition', type='range', subtype='integer', constraint='10000', column='user_id')
class PracticeAttempt(models.Model):
    id              = models.AutoField(primary_key=True)
    user_id         = models.IntegerField()
    question_id     = models.IntegerField()
    time_taken      = models.IntegerField(default=0)    
    num_attempts    = models.IntegerField(default=1)
    start_time      = models.DateTimeField()        
    bookmark        = models.IntegerField(default=0)

    class Meta:
        app_label = settings.APP_SUBMISSION
        db_table = 'practice_attempts'
        unique_together = ('user_id', 'question_id')

在插入数据时,我收到此错误

  

PartitionRangeSubtypeError:不支持的分区范围子类型"日期"在" PracticeSubmission"模型,支持范围子类型为" mysql"数据库是:date。

我甚至尝试subtype = "date", constraint = "year" & column = "start_time",但我仍然遇到同样的错误。请帮帮我。

1 个答案:

答案 0 :(得分:0)

错误提示问题出在PracticeSubmission,而不是PracticeAttempt。如果PracticeSubmission继承自PracticeAttempt,则需要修饰它,以便架构师可以忽略它:

@architect.install('partition', type='range', subtype='integer', constraint='10000', column='user_id')
class PracticeAttempt(models.Model):
    id              = models.AutoField(primary_key=True)
    user_id         = models.IntegerField()
    question_id     = models.IntegerField()
    time_taken      = models.IntegerField(default=0)    
    num_attempts    = models.IntegerField(default=1)
    start_time      = models.DateTimeField()        
    bookmark        = models.IntegerField(default=0)

    class Meta:
        app_label = settings.APP_SUBMISSION
        db_table = 'practice_attempts'
        unique_together = ('user_id', 'question_id')



@architect.uninstall('partition')
class PracticeSubmission:
    ...