Reputation: 17292
I've found similar questions but they were in the app, mine relates to the cli commands, i.e. php app/console doctrine:schema:update --force
or php app/console doctrine:migrations:migrate
Error:
Migration 20130112151503 failed during Execution. Error An exception occurred wh
ile executing 'CREATE UNIQUE INDEX UNIQ_68D3801E989D9B62 ON artists (slug)':
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key
'UNIQ_68D3801E989D9B62'
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'CREATE UNIQUE INDEX UNIQ_68D3801E989
D9B62 ON artists (slug)':
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' fo
r key 'UNIQ_68D3801E989D9B62'
I was really hoping that migrations would take care of this error, but alas. How do I resolve this issue, e.g. I would only be able to run the migrations command on the live server. Why doesn't the migration first drop the unique index if exists? Or why doesn't it detect there is already an unique index?
Upvotes: 0
Views: 5578
Reputation: 477
This is because the slug
field in your database is empty or duplicate. So, try to delete everything in your table and generate again the command
Upvotes: 0
Reputation: 2374
That SQL error isn't saying there is already a unique index, it's saying that the slug column has duplicate values and it can't add the index because of it.
Ensure that the slug column only has unique (or null, but probably not recommended for a slug column) values, and then try to run the migration again.
Upvotes: 3