django migrate有错误:指定USING表达式以执行转换

use*_*364 8 python django postgresql

我将我的模型字段从Charfiled()更改为GenericIPAddressField()

ip = models.GenericIPAddressField()
Run Code Online (Sandbox Code Playgroud)

并使用django 1.7迁移

./manage.py makemigrations core
./manage.py migrate
Run Code Online (Sandbox Code Playgroud)

但是有错误:

return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "ip" cannot be cast automatically to type inet
HINT:  Specify a USING expression to perform the conversion.
Run Code Online (Sandbox Code Playgroud)

我试试这个,但不行:

ALTER TABLE core_message ALTER COLUMN ip TYPE inet USING (ip::inet);
Run Code Online (Sandbox Code Playgroud)

错误:

ERROR:  invalid input syntax for type inet: ""
Run Code Online (Sandbox Code Playgroud)

我现在能做什么?
请帮帮我谢谢!

pan*_*ore 9

一个快速解决方法是删除并创建字段:

  1. 删除迁移正在更改字段类型的内容.
  2. 删除/评论该字段 ip
  3. 进行迁移
  4. ip使用新字段类型返回/取消注释该字段
  5. 进行迁移
  6. 迁移

我在生产中这样做,并使用先前的csv备份和几行代码的python脚本恢复数据.