我有django模型带字段
locations = JSONField(default=list, blank=True)
我想使用:
将字段类型更改为ArrayFieldlocations = ArrayField(CharField(max_length=100))
django makemigrations创建了迁移文件:
operations = [
migrations.AlterField(
model_name='Employee',
name='locations',
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), size=None),
),
]
但是在运行迁移时会抛出错误:
django.db.utils.ProgrammingError: cannot cast type jsonb to character varying[]
LINE 1:...“locations”TYPE varchar(100)[]使用“locations”:: varchar(...
将jsonb list字段更改为arrayfield的正确方法是什么?如何在运行迁移时将jsonb强制转换为arrayfield?