JSONField in PostgreSQL varchar limit 256

Hi All,

I’ve been searching for solution for a while now and can’t find a way to change the default length of the JSONField in PostgreSQL. I know it’s stored as VarChar (checked it in the database) and the length is 256. I guess this is some default value somewhere (PostgreSQL or Django CharField?).
I did a workaround now and just defined my field as CharField with set_ and get_ also defined in the model, but it’s not elegant.

Do I miss something in JSONField?

Thanks folks!

That must be an artifact of an older database or migration. The current versions of PostgreSQL stores a JSONField as a JSONB field type.

I have started with a new database, PostgreSQL 13, and erased all the migration files in Django before makemigration and migrate.
But maybe I did an initial migration before, with the CharField solution and then the field type has not changed in PostgreSQL after new migration requests (even with no migration files in Django)

I will try and delete all the tables again and see what happens.

When I start from an empty database Django creates JSONB field type indeed. Unfortunately the migration doesn’t change it. Can we report it somewhere?

What do you mean by “the migration doesn’t change it”? A lot depends upon what was done from the very beginning and how migrations were handled along the way. Are you saying that this was originally a VarChar field and then changed to a JSON Field?

If you don’t have a continuous and uninterrupted chain of migration files from initial table creation to present, I don’t think there’s anything to report. (On the other hand, if you’ve got such a chain that shows that field was originally a CharField, then subsequently changed to a JSONField and no ALTER TABLE was generated, that might be worth reporting.)