简体   繁体   English

Django Postgres ArrayField(models.IntegerField) 迁移错误

[英]Django Postgres ArrayField(models.IntegerField) migration error

I am new to Django and my aim is to store a list of integers in Django model using ArrayField but when I run migrations it gives the following error我是 Django 的新手,我的目标是使用ArrayField将整数列表存储在 Django model 中,但是当我运行迁移时,它会给出以下错误

django.db.utils.ProgrammingError: column "object_ids" is of type integer[] but default expression is of type integer
HINT:  You will need to rewrite or cast the expression.

The field that i am using is:我正在使用的领域是:

ids=ArrayField(models.IntegerField(null=True, blank=True), null=True, blank=True)

Any help would be appreciated任何帮助,将不胜感激

You can try this你可以试试这个

from django.db import models
from django.contrib.postgres.fields import ArrayField
# Create your models here.
class YourModel(models.Model):
    ids = ArrayField(models.IntegerField(),null=True, blank=True)

More information here https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/fields/#arrayfield更多信息在这里https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/fields/#arrayfield

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

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