简体   繁体   English

Django:分区表的外键

[英]Django: Foreign Key to a partitioned table

I have used architect to partition an existing table. 我已经使用架构师对现有表进行分区。

@architect.install('partition', type='range', subtype='integer', constraint='100', column='id')
class Project(models.Model):
    name = models.CharField(max_length=150)

The project model was used as a foreign key to another model. 项目模型被用作另一个模型的外键。

class ProjectChangeLog(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE)

After partitioning, I could not add any ProjectChangeLog objects. 分区后,我无法添加任何ProjectChangeLog对象。 It says: 它说:

IntegrityError: insert or update on table "logging_projectchangelog" violates foreign key constraint 
DETAIL:  Key (project_id)=(231) is not present in table "project_project"

One of the Limitations of partitions is that you can't have foreign keys pointing to them. 分区的局限性之一是您不能有指向它们的外键。 One workaround for this is to use custom constraints to mimic ForeignKey behavior. 一种解决方法是使用自定义约束来模仿ForeignKey行为。 This method can help you. 方法可以为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM