Django将imagefield转换为外键UUID

Django将imagefield转换为外键UUID,django,postgresql,django-migrations,Django,Postgresql,Django Migrations,我有django项目,我有imagefield,如下所示 certificate=models.ImageFieldnull=True,blank=True,最大长度=1000 但是我需要将imagefield更改为外键UUID,如下所示 certificate=models.ForeignKeyCertificates,null=True,blank=True,on_delete=models.CASCADE 但我得到的迁移错误如下所示 Applying templates.0016_auto

我有django项目,我有imagefield,如下所示

certificate=models.ImageFieldnull=True,blank=True,最大长度=1000

但是我需要将imagefield更改为外键UUID,如下所示

certificate=models.ForeignKeyCertificates,null=True,blank=True,on_delete=models.CASCADE

但我得到的迁移错误如下所示

Applying templates.0016_auto_20200502_0452...Traceback (most recent call last):
File "/home/sakthips/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
   return self.cursor.execute(sql, params)
psycopg2.DataError: invalid input syntax for type uuid: ""

这个错误有点奇怪,有人能帮我解决吗。我知道我可以删除现有字段并添加新字段,这是一种解决方案。我在等待其他解决方案。

在更改证书图像字段之前,它可能有列证书的数据。因此,django希望将数据修改为一种新的类型,有时某些数据无法转换,从而导致错误

有两种解决方法: 打开数据库,删除目标表的相关列。 注释相关功能模型和表单中的证书列,然后进行迁移并迁移到drop certificate列。取消对CertificateKey列和相关表单的注释,然后重做makemigrations和migrate以添加新的certificate\u id列。 希望对你有帮助