Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff error : "An index with name ... was already defined on table '...'. " #3828

Open
psohm opened this issue Jan 17, 2020 · 9 comments
Open

Comments

@psohm
Copy link

psohm commented Jan 17, 2020

Bug Report

Q A
BC Break no
Version 2.7.0

Summary

Doctrine diff fail on some configuration

Current behaviour

When I make a doctrine:diff Doctrine tryes to create index for 2 different Entity mapped with a OneToOne association
I have an error

An index with name 'uniq_19653dbdbf396750' was already defined on table 'societe'.

How to reproduce

class Societe
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false, options={"unsigned"=true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;
    /**
     * @var VueContrat
     * @ORM\OneToOne(targetEntity="VueContrat")
     * @ORM\JoinColumn(name="id", referencedColumnName="idsociete")
     */
    private $statut;

    /**
     * @var VueCo|null
     * @ORM\OneToOne(targetEntity="VueCo")
     * @ORM\JoinColumn(name="id", referencedColumnName="id",nullable=true)
     */
    private $statutco;
}

You need to have 2 Entity named VueContrat and VueCo.
That 2 entity are Mysql View.

Expected behaviour

I expect to disable the creation for that 2 views.
We can reduce the problem using doctrine event listener but I didn't find the right event.
We can also have a solution if we can set the index name explicitely.

@morozov
Copy link
Member

morozov commented Jan 17, 2020

@psohm please reproduce using only the DBAL APIs.

@psohm
Copy link
Author

psohm commented Jan 17, 2020

hello I fear to miss your need
can you be more precise ?

@morozov
Copy link
Member

morozov commented Jan 17, 2020

Please see #2897 for example. A maintainer should be able to run the code you will provide and reproduce the issue. So far, there's not enough information on how to reproduce it.

@psohm
Copy link
Author

psohm commented Jan 17, 2020

I pushed a project with the problem.
https://github.com/psohm/doctrine-issue3828

@psohm
Copy link
Author

psohm commented Jan 17, 2020

Just for explain The two OneToOne relationship are view but it isn't necessary
If you use 2 tables it has the same results.

In SchemaException.php line 68:

An index with name 'uniq_19653dbdbf396750' was already defined on table 'societe'.

@psohm
Copy link
Author

psohm commented Jan 27, 2020

hi, did you manage to reproduce the issue ?

@morozov
Copy link
Member

morozov commented Jan 27, 2020

No, I currently don't have time to debug a Symfony project.

@Forestsoft-de
Copy link

Hi

the problem also occur if the Index name contains dots in its name:

image

[Doctrine\DBAL\Schema\SchemaException (60)]
An index with name 'fk.app' was already defined on table 'app'.

@popov654
Copy link

No, I currently don't have time to debug a Symfony project.

Erm, what? Isn't DBAL a Doctrine component, and isn't Doctrine mainly used in Symfony applications? I have the exact same error at the moment, the only difference is that I have 3 entities (one main and two auxilary) and I'm trying to link them together in two OneToOne relationships using the same PK values in 3 MySQL tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants