django.db.utils.ProgrammingError: cannot cast type text[] to jsonb

Viewed 6187

I was trying to include JSONField in my model:

from django.contrib.postgres.fields import JSONField
class Trigger(models.Model):
    solutions = JSONField(blank=True, null=True)

However, when I try to migrate the database, it gives the following error:

django.db.utils.ProgrammingError: cannot cast type text[] to jsonb
LINE 1: ...ALTER COLUMN "solutions" TYPE jsonb USING "solutions"::jsonb

What could be done here?

2 Answers

You can update the migration file from

operations = [
    migrations.AlterField(
        model_name='foo',
        name='bar',
        field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict),
    ),
]

to

operations = [
    migrations.RemoveField(
        model_name='foo',
        name='bar',
    ),
    migrations.AddField(
        model_name='foo',
        name='bar',
        field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict),
    ),
]
Related