Wednesday, October 30, 2019

UNIQUE constraint failed on adding a new model field

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)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/be29e076-3727-469e-9621-b4ca09dc7c6b%40googlegroups.com.

No comments:

Post a Comment