开发者

Doctrine 2 multiple primary keys

For some reason doctrine is trying to insert an index called primary instead of actually adding a primary key on 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;
}


Adding info about Multi-column Unique constraints here because this is what came up when I googled 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜