【问题标题】:Symfony2 @UniqueEntity constraint on 2 foreign keys not workingSymfony2 @UniqueEntity 对 2 个外键的约束不起作用
【发布时间】:2015-09-09 16:17:24
【问题描述】:
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@UniqueEntity({"store_id","user_id"})

php 应用程序/控制台原则:schema:update --force

无需更新 - 您的数据库已与当前数据库同步 实体元数据。

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

【问题讨论】:

    标签: php postgresql symfony doctrine-orm symfony-2.7


    【解决方案1】:

    试试:

    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
    {
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      相关资源
      最近更新 更多