I work on a Django 1.8 project that uses the old django-json-field library. I want to remove the library, update to Django 1.9 and use the native JSONField, but I have migrations that rely on the JSONField from the old library, so I can't remove it. I also can't update Django without removing it because it is deprecated and causes errors when I try to update Django. What's the correct way to proceed in this situation?
Asked
Active
Viewed 543 times
0
-
1Use a `CharField` as an intermediate way to store the JSON? – Willem Van Onsem Aug 06 '18 at 12:17
-
1Use [RunPython](https://docs.djangoproject.com/en/2.1/ref/migration-operations/#django.db.migrations.operations.RunPython) – JPG Aug 06 '18 at 12:19
-
a similar RunPython example , [here](https://stackoverflow.com/questions/49221515/how-can-i-set-provide-a-default-value-while-django-migration) – JPG Aug 06 '18 at 12:21
-
@WillemVanOnsem has the right idea, since `django-json-field` is actually just a `TextField` wrapper (ref: [source](https://github.com/dmkoch/django-jsonfield/blob/master/jsonfield/fields.py#L154)) – Burhan Khalid Aug 06 '18 at 12:21
-
@Ariel Does Django support native JSON? Can you share some reff? – JPG Aug 06 '18 at 12:24
-
Its only supported for postgresql; as it has a native json column type. For all others its just a text field wrapper with a custom serializer. See the [docs](https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/fields/#jsonfield) for more details. – Burhan Khalid Aug 06 '18 at 12:26
-
@JerinPeterGeorge https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#jsonfield – Ariel Aug 06 '18 at 12:42
1 Answers
0
As suggested by Burhan Khalid on his comment above, a solution would be to
- Copy that deprecated json-field to a text column
- Create that migration
- Delete the deprecated json-field
- Create this migration
- With no trace of the deprecated json-field, remove the package. Test that everything is OK and upgrade your app.
If this doesn't work (probably because that json-field is referenced elsewhere) you'll have to just change that field to text in your models.py and then make it through migrations.

thlik
- 401
- 6
- 12