UNIQUE constraint failed on adding a new model field

16 views
Skip to first unread message

Vahid Asadi

unread,
Oct 30, 2019, 1:27:10 PM10/30/19
to Django users

HI . when i want to add a new field called "slug" to my "Post" model, the migrate command will raise UNIQUE constraint failed: new__chat_post.slug

after that i remove that field from my model but the problem still exists. why?? and how to resolve this problem without deleting my whole table datas. thanks ..

the model:


class Post(models.Model):    
    title = models.TextField(max_length=100)
    context = models.TextField(max_length=255)
    creation_date  = models.DateTimeField(default = timezone.now)
    author = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete = models.CASCADE)
    slug = models.SlugField(default=["title"],unique=True)
Reply all
Reply to author
Forward
0 new messages