Hi, As I said in previous email, first I thought I am getting the error: [Doctrine\DBAL\Schema\SchemaException] An index with name 'uniq_71260315bf396750' was already defined on table 'items'.
because I was defining joinColumns on owning sides too, I removed joinColumns from owning side then I get this error: Column name `id` referenced for relation from Entity\B towards Entity\A does not exist. That was because of the PK a_id, I renamed them in "id" and edited name/referenceName as appropriate, now the error above has gone, but again I am getting that index error, so now this is clear that error had nothing to do with defining joinColumns on owning sides. My mappins are indeed correct as they are validated by dbal 2.5.0, so I think I should assume there is a bug with dbal 2.5.1. Any advice? On Thu, Jul 2, 2015 at 1:46 PM, Nima Sadjadi <[email protected]> wrote: > Hi, > > Thanks for trying to help: > As about "unique" I was wrong, I meant "id" of a_id in all A,B, C entities > are set to true. > mappings in A entity to B and C: > > $metadata->mapOneToOne(array( 'fieldName' => 'B', > 'targetEntity' => 'Entity\\B', > 'mappedBy' => 'A', > 'cascade' => array( 0 => 'remove', 1 => 'persist', ), > 'joinColumns' => array( 0 => array( 'name' > => 'a_id', > > 'referencedColumnName' => 'a_id', > > 'nullable' => true, > 'onDelete' => 'cascade', > > 'columnDefinition' => NULL, > ), ) > )); > > $metadata->mapOneToOne(array( 'fieldName' => 'C', > 'targetEntity' => 'Entity\\C', > 'mappedBy' => 'A', > 'cascade' => array( 0 => 'remove', 1 => 'persist', ), > 'joinColumns' => array( 0 => array( 'name' > => 'a_id', > > 'referencedColumnName' => 'a_id', > > 'nullable' => true, > 'onDelete' => 'cascade', > > 'columnDefinition' => NULL, > ), ) > > )); > > mapping in B entity to A: > > In B entity: > $metadata->mapOneToOne(array( 'fieldName' => 'A', > 'targetEntity' => 'Entity\\A', > 'inversedBy' => 'B', > 'joinColumns' => array( 0 => array( 'name' > => 'a_id', > > 'referencedColumnName' => 'a_id', > > 'nullable' => true, > > 'columnDefinition' => NULL, > ), ) > > )); > > mapping in C entity to A: > $metadata->mapOneToOne(array( 'fieldName' => 'A', > 'targetEntity' => 'Entity\\A', > 'inversedBy' => 'C', > 'joinColumns' => array( 0 => array( 'name' > => 'a_id', > > 'referencedColumnName' => 'a_id', > > 'nullable' => true, > > 'columnDefinition' => NULL, > ), ) > > )); > > > I also tried to remove 'joinColumns' from owning sides too: > > $metadata->mapOneToOne(array( 'fieldName' => 'A', > 'targetEntity' => 'Entity\\A', > 'inversedBy' => 'C' > )); > But in that case I get > Column name `id` referenced for relation from Entity\B towards Entity\A > does not exist. > As you noticed I have a_id. > > What do you advice to do? what wrong I did? > > > On Thu, Jul 2, 2015 at 11:49 AM, Menno Holtkamp <[email protected]> > wrote: > >> Please provide your mapping information. Possibly in a Gist at GitHub. >> >> This part of your description seem awkward to me: >> >> *"In each of B and C, a_id has: unique=true as it is primary key but I >> have:* >> >> *$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);instead >> of >> GENERATOR_TYPE_IDENTITY to tell the entity that this primary key is not >> auto-incrementing as it is FK too."* >> >> Why would you have other Entities (B and C) define metadata about Entity >> A? >> >> I would say you try to define stuff too strict, let Doctrine do that hard >> work for you. Maybe in the last DBAL version a conflict that existed in >> your mapping for a while, is now generating an error because of new checks. >> I would assume Doctrine DBAL is correct in that ;) >> >> Cheers >> >> On 27 June 2015 at 21:22, Nima Sadjadi <[email protected]> wrote: >> >>> >>> Also I created a blank db, and tried to create tables with >>> orm:schema-tool:create --dump-sql >>> I am still getting the same error, and in two previous emails, I >>> described how to replicate the error. >>> Doesn't it look like a bug in dbal 2.5.1? 2.5.0 works fine. >>> Please advice. >>> >>> >>> On Sat, Jun 27, 2015 at 10:22 PM, Nima Sadjadi <[email protected]> >>> wrote: >>> >>>> >>>> Hi, >>>> >>>> In previous email I described why and how that error occurs, I also >>>> discovered that if I keep orm version 2.5.0 but with dbal 2.5.0 instead of >>>> dbal 2.5.1, the problem solved! so the issue is changes in dbal 2.5.1 vs >>>> dbal 2.5.0. nothing to do with orm at all. >>>> What are major changes in dbal 2.5.1 that causes this problem? >>>> >>>> >>>> >>>> On Sat, Jun 27, 2015 at 8:19 PM, Nima Sadjadi <[email protected]> >>>> wrote: >>>> >>>>> >>>>> Hello, >>>>> >>>>> Thanks for trying to help, After lots of testing, I discovered the >>>>> problem: >>>>> I have A table oneToOne to two tables, B and C via the same id and FK >>>>> in both. I mean: >>>>> >>>>> A OneToOne with B: name: id, referenceColoumn: a_id >>>>> A OneToOne with C: name: id, referenceColoumn: a_id >>>>> >>>>> in tables B and C, the coloumn a_id is Primary key of B and C. because >>>>> the only mappings in each of B and C, is OneToOne mapping to A, so a_id is >>>>> both FK and primary key, >>>>> >>>>> In each of B and C, a_id has: unique=true as it is primary key but I >>>>> have: >>>>> $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); >>>>> instead of GENERATOR_TYPE_IDENTITY to tell the entity that this >>>>> primary key is not auto-incrementing as it is FK too. >>>>> >>>>> The older doctrine version had no problem with this all, but in the >>>>> latest version, it gives that error, if an entity has OneToOne mapping >>>>> with >>>>> two other entities via the same primary key, is it a bug in latest >>>>> version? >>>>> If I remove one of these mappings from A, then it is solved, but I >>>>> need mappings to both B and C in A. How can I solve this? please advice as >>>>> I am stuck. >>>>> >>>>> Many thanks in advance. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> On Wed, Jun 24, 2015 at 8:25 AM, Barrie Treloar <[email protected]> >>>>> wrote: >>>>> >>>>>> >>>>>> >>>>>> On Tuesday, June 23, 2015 at 8:34:17 AM UTC+9:30, Parsifal wrote: >>>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> since I updated orm to 2.5.0 and dbal to 2.5.1 when I want to run >>>>>>> validate-schema command on console I get the error: >>>>>>> >>>>>>> [Doctrine\DBAL\Schema\SchemaException] >>>>>>> An index with name 'uniq_71260315bf396750' was already defined on >>>>>>> table 'items'. >>>>>>> >>>>>>> Actually I did not define any index with that name in that table, I >>>>>>> have just one primary key. Older doctrine version had no such problem. I >>>>>>> did search the group and saw some discussions, but I did not understand >>>>>>> this is a confirmed bug or how can I solve this issue? please advice. >>>>>>> >>>>>>> >>>>>> If your table can be shared, can you provide your Doctrine table >>>>>> yaml/annotations? >>>>>> >>>>>> The uniq_<hash> tells me it is an auto-generated index. >>>>>> >>>>>> You can use >>>>>> php app/console doctrine:schema:create --dump-sql >>>>>> to show you the commands that would be used to create your schema, >>>>>> you can then see which ones cause duplicates. >>>>>> >>>>>> I suspect that you have are using a combination of annotations that >>>>>> is causing the trouble. >>>>>> >>>>>> http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#annref-index >>>>>> >>>>>> e.g. I use >>>>>> @ORM\Index to rename all my primary key indexes. >>>>>> @ORM\UniqueConstraint for non-key indxes >>>>>> >>>>>> But I am not using >>>>>> @ORM\Column{unique=true} >>>>>> >>>>>> I think this also causes the index to be created but you can't >>>>>> control the name at this point, and so when I had both I had your >>>>>> problem. >>>>>> However, this was a while ago, and I've forgotten the exact cause/ >>>>>> >>>>>> Also, this is the first time I'm using Doctrine, so I really dont >>>>>> know what I am talking about. I've just bumbled along well enough so far. >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "doctrine-user" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to [email protected]. >>>>>> To post to this group, send email to [email protected]. >>>>>> Visit this group at http://groups.google.com/group/doctrine-user. >>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>> >>>>> >>>>> >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "doctrine-user" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/doctrine-user. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "doctrine-user" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/doctrine-user. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
