Doctrine 2 multiple primary keys

For some reason, the doctrine is trying to insert an index called primary instead of actually adding the primary key to my MYSQL database, this is what Doctrine generates:

CREATE UNIQUE INDEX primary ON my_table (columnOne, columnTwo); 

This is what my SQL editor generates, and this is the only method that works:

 ALTER TABLE my_table ADD PRIMARY KEY (columnOne,columnTwo); 

This is my class:

 .... class MyTable { /** * @var integer $columnOne * * @Column(name="columnOne", type="integer", nullable=false) * @Id * @GeneratedValue(strategy="NONE") */ private $columnOne; /** * @var integer $columnTwo * * @Column(name="columnTwo", type="integer", nullable=false) * @Id * @GeneratedValue(strategy="NONE") */ private $columnTwo; } 
+6
source share
2 answers

The answer is yes and no . Please check out this blog post:

http://www.doctrine-project.org/blog/dc2-experimental-associations-id-fields.html

+2
source

Adding information on unique constraints with multiple columns here, because that is what appeared when I searched for it.

If you want something like this SQL:

 CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName) 

use this annotation in Doctrine2

 @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "email"})}) 

see http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/annotations-reference.html#uniqueconstraint

+1
source

Source: https://habr.com/ru/post/885983/


All Articles