IntegrityError: column pool is not unique

I study django with tangowithdjango textbooks, and there on the 7th chapter that I laid out.

I am trying to include the slug field in my model and override the save method so that it all works. After migration, I have an integrity error.

models.py:

class Category(models.Model):

    name = models.CharField(max_length=128, unique=True)
    views = models.IntegerField(default=0)
    likes = models.IntegerField(default=0)
    slug = models.SlugField(unique=True)

    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(Category, self).save(*args, **kwargs)

    class Meta:
        verbose_name_plural = "Categories"

    def __unicode__(self):
        return self.name

Thank!

+4
source share
1 answer

Listen to the mistake. You have the slug attribute specified as unique, but for multiple instances of your class Categoryyou must have the same slug value.

, , , , , .

...

, slug-, unqiue, Category , .

,

migrations.AddField(
    model_name='category',
    name='slug',
    field=models.SlugField(unique=True),
    preserve_default=False,
),

migrations.AddField(
    model_name='category',
    name='slug',
    field=models.SlugField(null=True, blank=True),
    preserve_default=False,
),

python manage.py migrate ( django 1.7. South ), django python manage.py shell,

for cat in Category.objects.all():
    cat.slug = cat.name
    cat.save()

, slug . , , , .

+8

Source: https://habr.com/ru/post/1570071/


All Articles