Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate index on sqlite, not on mysql

I have a entity definition that works on dev and production envs (mysql), but not on test (sqlite):

/**
 * Invoice
 *
 * @ORM\Table(name="invoice", indexes={
 *     @ORM\Index(name="ref_idx", columns={"ref"}),
 *     @ORM\Index(name="created_at_idx", columns={"created_at"}),
 *     @ORM\Index(name="paid_idx", columns={"paid"}),
 *     @ORM\Index(name="is_valid_idx", columns={"is_valid"}),
 *     @ORM\Index(name="canceled_idx", columns={"canceled"})
 * })
 * @ORM\Entity(repositoryClass="AppBundle\Repository\InvoiceRepository")
 */
class Invoice
// [...]

When I run doctrine:schema:create or doctrine:schema:update --force on test env, I have the following error:

  [Doctrine\DBAL\DBALException]                                                                 
  An exception occurred while executing 'CREATE INDEX created_at_idx ON invoice (created_at)':  
  SQLSTATE[HY000]: General error: 1 index created_at_idx already exists                         


  [PDOException]                                                         
  SQLSTATE[HY000]: General error: 1 index created_at_idx already exists 

Is someone already had this kind of issue? How to solve/ignore it?

Thanks.

like image 702
Soullivaneuh Avatar asked Dec 01 '14 22:12

Soullivaneuh


1 Answers

The solution is here: https://stackoverflow.com/a/24634713/1731473

In a nutshell, your index must have a unique name across your database.

So you can't have:

  • invoice -> created_at_idx
  • user -> created_at_idx

But:

  • invoive -> invoice_created_at_idx
  • user -> user_created_at_idx
like image 134
Soullivaneuh Avatar answered Nov 05 '22 20:11

Soullivaneuh