Symfony2 @UniqueEntity 对 2 个外键的约束不起作用

Symfony2 @UniqueEntity constraint on 2 foreign keys not working

use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@UniqueEntity({"store_id","user_id"})

php app/console doctrine:schema:update --force

Nothing to update - your database is already in sync with the current entity metadata.

我尝试再次删除并创建 table,但没有创建唯一键。

尝试:

use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

@UniqueEntity(fields={"store_id","user_id"})

请记住验证器与底层数据库架构无关,它只是验证对象的当前状态。如果您想创建自定义唯一索引,请参阅 @UniqueConstraint annotation in doctrine:

/**
 * @Entity
 * @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"store_id", "user_id"})})
 */
class ECommerceProduct
{
}