You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The migration replacing jsonfield.fields.JSONField with Django’s built-in models.JSONField does not correctly migrate PostgreSQL columns from text to jsonb.
As a result, upgraded installations may still have columns typed as text while Django ORM starts generating jsonb queries/operators for these fields, causing errors such as::
ALTER TABLE <table_name>
ALTER COLUMN <column_name>
TYPE jsonb
USING <column_name>::jsonb;
Expected behavior
The migration should generate PostgreSQL ALTER COLUMN ... TYPE jsonb statements so existing text columns are correctly converted to jsonb.
Possible solution
Do not replace historical jsonfield.fields.JSONField usages in old migration files with models.JSONField.
Since the original third-party JSONField inherited from models.TextField, preserving the historical field as TextField allows Django to correctly detect the transition from text to jsonb and generate the required SQL migration.
Describe the bug
The migration replacing
jsonfield.fields.JSONFieldwith Django’s built-inmodels.JSONFielddoes not correctly migrate PostgreSQL columns fromtexttojsonb.As a result, upgraded installations may still have columns typed as
textwhile Django ORM starts generatingjsonbqueries/operators for these fields, causing errors such as::The issue was introduced in #742
Steps To Reproduce
Note
This issue can only be reproduced on PostgreSQL.
Install version
1.2of openwisp-monitoring.Run migrations::
Upgrade to the current
masterbranch containing thejsonfield.fields.JSONField->models.JSONFieldreplacement.Inspect the migration SQL::
Observe that Django generates::
instead of::
Expected behavior
The migration should generate PostgreSQL
ALTER COLUMN ... TYPE jsonbstatements so existingtextcolumns are correctly converted tojsonb.Possible solution
Do not replace historical
jsonfield.fields.JSONFieldusages in old migration files withmodels.JSONField.Since the original third-party
JSONFieldinherited frommodels.TextField, preserving the historical field asTextFieldallows Django to correctly detect the transition fromtexttojsonband generate the required SQL migration.