Django的JSONField [英] Django JSONField

查看:565
本文介绍了Django的JSONField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我们一直在使用 jsonfield 库中的JSONField,但现在我们想要使用本机 PostgreSQL JSONField .因此,我想知道是否有可能更改现有模型的字段类型,以保留旧的字段名称而又不丢失任何数据.谢谢.

We have been using JSONField from jsonfield library for a while, but now we want to use native PostgreSQL JSONField. So I would like to know whether it is possible to change field types for existing models preserving old field names and without loosing any data. Thanks.

推荐答案

您想要做的是数据迁移.

  1. 保留现有的jsonfield并添加新的PostreSQL JSONField.
  2. 生成一个数据迁移,该迭代过程每条记录都将数据从旧字段迁移到新字段.
  3. 运行迁移后,您可以弃用旧字段并将其删除,而不会造成任何数据丢失.
  1. Keep the existing jsonfield and add the new PostreSQL JSONField.
  2. Generate a data migration, which iterates through each record migrating the data from the old field to the new one.
  3. Once you've run the migration you can deprecate the old field and remove it without any data loss.

参考文献

Django数据迁移

这篇关于Django的JSONField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆