4

有没有办法将 FK 选项(db_constraint、on_delete 等)应用于使用多表继承时自动创建的“_ptr”列?我想阻止 Django 模拟删除级联行为并让数据库本地执行该行为。

4

1 回答 1

2

我找到了一种方法来做到这一点:

class Article(models.Model):
    name = models.CharField()

class PersonalArticle(Article):
    user = models.ForeignKey('auth.User')

PersonalArticle._meta.get_field('article_ptr').rel.on_delete = models.DO_NOTHING
于 2015-04-01T13:43:46.293 回答