Skip to content Skip to sidebar Skip to footer

Django Change Model's Field Type From CharField To JSONField

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, accor

Solution 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


Post a Comment for "Django Change Model's Field Type From CharField To JSONField"