无法将类型字符variant []强制转换为jsonb django迁移 [英] cannot cast type character varying[] to jsonb django migration

查看:115
本文介绍了无法将类型字符variant []强制转换为jsonb django迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在收到错误

无法将类型字符variant []强制转换为jsonb 第1行:... LUMN"questionaires" TYPE jsonb使用"questionaires" :: jsonb.

cannot cast type character varying[] to jsonb LINE 1: ...LUMN "questionaires" TYPE jsonb USING "questionaires"::jsonb.

如何解决此问题?以及它是如何发生的?

How to fix this ? and how it did occur?

来自

questionaires   = ArrayField(models.CharField(max_length=4000), null=True, blank=True)

questionaires   = JSONField(null = True,blank = True)

推荐答案

我认为您必须执行多阶段迁移:

I think you have to perform multiple stage migrates:

  1. 创建类型为JSONField的临时新字段:Ex Questionaires_2
  2. 编写自定义python迁移 RunPython 手动转换数据
  3. 删除旧字段:问卷调查者
  4. 将临时字段重命名为旧的问卷调查器_2->问卷调查器
  1. Create temporary new field with type JSONField: Ex questionaires_2
  2. Write custom python migration RunPython to convert data manually
  3. Delete old field: questionaires
  4. Rename temporary field to the old one questionaires_2 -> questionaires

更多信息:请参见 https://stackoverflow.com/a/21997589/533738

未测试!

ALTER TABLE <Your Table>
ALTER COLUMN questionaires TYPE JSONB
      USING translate(questionaires::text, '{}','[]')::JSONB;

这篇关于无法将类型字符variant []强制转换为jsonb django迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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