【发布时间】:2023-03-17 06:21:01
【问题描述】:
这是我想要做的: 在 Django 中创建一个模型,它是一个 PostgreSQL 数组(数据库特定类型),其中包含另一个模型的外键。
class Books(models.Model):
authors = ArrayField(
models.ForeignKey('my_app.Authors', default=None, null=True, blank=True),
blank=True,
default=list()
)
当我尝试进行迁移时,Django 给了我这个错误:
SystemCheckError: System check identified some issues:
ERRORS:
my_app.Books.authors: (postgres.E002) Base field for array cannot be a related field.
关于如何打败它的任何想法?
【问题讨论】:
-
您应该为此使用
ManyToMany字段。
标签: django postgresql django-models django-orm django-migrations