【发布时间】:2018-05-22 21:25:57
【问题描述】:
我是 django 的新手,我尝试将 tag 字段从 char 字段更改为 TaggableManager()
models.py
class UserBookmark(models.Model):
user = models.ForeignKey(User)
bookmark = models.URLField()
tag = TaggableManager()
def __str__(self):
return '%i %s %s'%(self.id,self.user,self.bookmark)
当我运行 python manage.py migrate 时,我得到这个错误:
ValueError:无法将字段 bookmark.UserBookmark.tags 更改为 bookmark.UserBookmark.tags - 它们不是兼容的类型(您不能 更改 M2M 字段或从 M2M 字段更改,或通过 = 在 M2M 字段上添加或删除)
如何消除此错误?
【问题讨论】:
-
你在
migrate之前运行过makemigrations吗? -
@scharette no 我先迁移。
-
当您对模型进行更改时,您必须先运行
makemigrations。它将创建重新创建对数据库的更改所需的 sql 命令。然后你可以migrate这些变化。 -
@scharette 但是当我运行 python manage.py makemigrations 时,它说没有检测到任何变化。
-
@avleen01 试试 makemigrations