我试图向django模型添加一个属性,它显示了'django.db.utils.IntegrityError:唯一约束失败:‘错误。因此,我后退了,只是删除了属性,但它仍然显示了错误,所以请您如何永久删除该属性。
模型(实际上我已经从这里删除了属性)。
class Post(models.Model):
title = models.CharField(max_length=200, unique=True)
slug = models.CharField(max_length=200, unique=True)
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name="blog_posts")
updated_on = models.DateTimeField(auto_now_add=True)
content= models.TextField()
created_on = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(choices=STATUS, default=0)
class Meta:
ordering = ['-created_on']
def __str__(self):
return self.title
当我试图逆转迁移或执行其他迁移时的错误。
PS C:\Users\USER\Desktop\Tishas_Lifestyle> py manage.py migrate blog 0004
Operations to perform:
Target specific migration: 0004_post_desc, from blog
Running migrations:
Applying blog.0004_post_desc...Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py", line 413,
in execute
return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: UNIQUE constraint failed: new__blog_post.desc
The above exception was the direct cause of the following exception:
发布于 2021-01-09 16:27:51
当你删除你添加的新的进贡,你就得去cmd
py manage.py makemigrations
如果仍然无法工作,请尝试删除迁移文件或整个数据库。
https://stackoverflow.com/questions/65642379
复制相似问题