-1

I'm not understanding this. I have seen the posts here Django - Slugs - Key (slug)=() is duplicated and here Django: Key (slug)=(*) already exists.

Here is my error message:

django.db.utils.IntegrityError: duplicate key value violates unique constraint "caseAT_case_slug_key" DETAIL: Key (slug)=() already exists.

In the docs it says: https://docs.djangoproject.com/en/1.8/howto/writing-migrations/#migrations-that-add-unique-fields Applying a “plain” migration that adds a unique non-nullable field to a table with existing rows will raise an error because the value used to populate existing rows is generated only once, thus breaking the unique constraint.

But this is NOT a migration. This is a djangoitem pipeline. The model has the slug being created automatically from the title. Therefore, I did not put slug in the pipeline. If it is expecting to create slug, and balks because it is already there, why isn't it also expecting to create all the other keys? If it isn't in the pipeline, why is it trying to create it now? Because it expects to create it? So I should remove the auto create on that field? Then how is it going to get created? I did want my slugs to be unique.

It seems circular and crazy to me, but what difference does that make? None. Your assistance appreciated.

Dennis Soemers
  • 8,090
  • 2
  • 32
  • 55
Malik A. Rumi
  • 1,855
  • 4
  • 25
  • 36
  • There's not nearly enough information here. This has nothing to do with migrations; the error is telling you that you're trying to create more than one item with an empty slug. But we have no way of knowing why the slug is empty, because you haven't shown any code. What is creating the item? What is supposed to be populating the slug field? – Daniel Roseman Feb 25 '18 at 11:58

1 Answers1

0

I have the solution for anyone coming after me. All I need to do is add null=True to the slugfield. It is not really a duplicate key. It is a duplicate value, '', represented as slug['']. See Alasdair's answer here: Django unique, null and blank CharField giving 'already exists' error on Admin page

Malik A. Rumi
  • 1,855
  • 4
  • 25
  • 36