0

I am using Django 1.11 , I have been using CharField in Models, and dumping data in it using json.dumps(). I am using mysql database.

I want to change CharField to JSONField, according to this answer. Is there any way so that I can modify my field type without loosing the data?

Please note that the data in CharField is json dumped.

Rakmo
  • 1,926
  • 3
  • 19
  • 37

1 Answers1

1

If you want to completely control the process write custom migration:

1) add new field of type JSONField null=True

2) copy data there using custom empty migration with with RunPython https://docs.djangoproject.com/en/2.0/ref/migration-operations/#django.db.migrations.operations.RunPython first

3) check everything was copied ok

4) remove old field

5) handle field rename eventually

andilabs
  • 22,159
  • 14
  • 114
  • 151