1
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.

I tried to delete and create the table again, there is no unique key created.

4

1 回答 1

1

尝试:

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

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

请记住,验证器与底层数据库模式无关,它只是验证对象的当前状态。如果您想创建自定义唯一索引,请参阅教义中的 @UniqueConstraint 注释

/**
 * @Entity
 * @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"store_id", "user_id"})})
 */
class ECommerceProduct
{
}
于 2015-09-09T16:30:39.143 回答