I have django model with field
locations = JSONField(default=list, blank=True)
I want to alter field type to ArrayField using:
locations = ArrayField(CharField(max_length=100))
django makemigrations created migration file as:
operations = [
migrations.AlterField(
model_name='Employee',
name='locations',
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), size=None),
),
]
But while running migration it throws error:
django.db.utils.ProgrammingError: cannot cast type jsonb to character varying[]
LINE 1: ... "locations" TYPE varchar(100)[] USING "locations"::varchar(...
What is the correct way of altering jsonb list field to arrayfield and how to typecast jsonb to arrayfield while running migration ?