2016-04-16 79 views
0

我正在使用ZF2的Doctrine 2。名稱'主'的索引已經在表'網站'上定義了

我有一個具有以下主鍵字段的網站實體。

/** 
* @var string 
* @ORM\Column(name="site_id", type="string", length=10, nullable=false) 
* @ORM\Id 
*/ 
private $siteId; 

及以下指標的

* @ORM\Table(name="sites", indexes={ 
* @ORM\Index(name="PRIMARY", columns={"site_id"}), 
* @ORM\Index(name="country_id", columns={"country_id"}), 
* @ORM\Index(name="timezone_id", columns={"timezone_id"}), 
* @ORM\Index(name="vat_rate_id", columns={"vat_rate_id"}), 
* @ORM\Index(name="site_mode_id", columns={"site_mode_id"}), 
* @ORM\Index(name="created_by_user_id", columns={"created_by_user_id"}), 
* }) 

當我在命令行中,我得到了以下錯誤消息運行php ./vendor/doctrine/doctrine-module/bin/doctrine-module orm:validate-schema

[Doctrine\DBAL\Schema\SchemaException] 
    An index with name 'primary' was already defined on table 'sites'. 

但是它也報告The mapping files are correct.

有誰知道爲什麼產生這個錯誤是什麼嗎?

非常感謝提前。

編輯

全部實體的要求

/** 
* Sites Entity 
* 
* @author Garry Childs 
* 
* @ORM\Table(name="sites", indexes={ 
* @ORM\Index(name="country_id", columns={"country_id"}), 
* @ORM\Index(name="timezone_id", columns={"timezone_id"}), 
* @ORM\Index(name="vat_rate_id", columns={"vat_rate_id"}), 
* @ORM\Index(name="site_mode_id", columns={"site_mode_id"}), 
* @ORM\Index(name="created_by_user_id", columns={"created_by_user_id"}), 
* }) 
* @ORM\Entity(repositoryClass="Application\Entity\Repository\SitesRepository") 
* @ORM\HasLifecycleCallbacks 
*/ 
class Sites extends AbstractEntity 
{ 

    /** 
    * @var string 
    * @ORM\Column(name="site_id", type="string", length=10, nullable=false) 
    * @ORM\Id 
    */ 
    private $siteId; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="domain_name", type="string", length=255, nullable=false) 
    */ 
    private $domainName; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="title", type="string", length=30, nullable=false) 
    */ 
    private $title; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="email_address", type="string", length=254, nullable=false) 
    */ 
    private $emailAddress; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="layout", type="string", length=30, nullable=true) 
    */ 
    private $layout; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="homepage", type="string", length=30, nullable=true) 
    */ 
    private $homepage; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="bookmark_icon", type="string", length=20, nullable=false) 
    */ 
    private $bookmarkIcon = 'bookmark.png'; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="address", type="string", length=200, nullable=false) 
    */ 
    private $address; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="town", type="string", length=30, nullable=false) 
    */ 
    private $town; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="county", type="string", length=30, nullable=false) 
    */ 
    private $county; 

    /** 
    * @var \Application\Entity\Countries 
    * 
    * @ORM\ManyToOne(targetEntity="Application\Entity\Countries") 
    * @ORM\JoinColumns({ 
    * @ORM\JoinColumn(name="country_id", referencedColumnName="country_id") 
    * }) 
    */ 
    private $country; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="post_code", type="string", length=7, nullable=false) 
    */ 
    private $postCode; 

    /** 
    * @var \Application\Entity\Timezones 
    * 
    * @ORM\ManyToOne(targetEntity="Application\Entity\Timezones") 
    * @ORM\JoinColumns({ 
    * @ORM\JoinColumn(name="timezone_id", referencedColumnName="timezone_id") 
    * }) 
    */ 
    private $timezone; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="locale", type="string", length=5, nullable=false) 
    */ 
    private $locale; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="currency_code", type="string", length=3, nullable=false) 
    */ 
    private $currencyCode; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="vat_number", type="string", length=10, nullable=true) 
    */ 
    private $vatNumber; 

    /** 
    * @var \Application\Entity\VatRates 
    * 
    * @ORM\ManyToOne(targetEntity="Application\Entity\VatRates", inversedBy="sites") 
    * @ORM\JoinColumns({ 
    * @ORM\JoinColumn(name="vat_rate_id", referencedColumnName="vat_rate_id") 
    * }) 
    */ 
    private $vatRate; 

    /** 
    * @var \DateTime 
    * 
    * @ORM\Column(name="date_created", type="datetime") 
    */ 
    private $dateCreated; 

    /** 
    * @var \DateTime 
    * 
    * @ORM\Column(name="date_modified", type="datetime") 
    */ 
    private $dateModified; 

    /** 
    * @var \Application\Entity\Users 
    * 
    * @ORM\ManyToOne(targetEntity="Application\Entity\Users") 
    * @ORM\JoinColumns({ 
    * @ORM\JoinColumn(name="created_by_user_id", referencedColumnName="user_id") 
    * }) 
    */ 
    private $createdBy; 

    /** 
    * @var Doctrine\ORM\PersistentCollection 
    * 
    * @ORM\OneToMany(targetEntity="Application\Entity\Categories", mappedBy="site") 
    */ 
    private $categories; 

    /** 
    * @var \Doctrine\ORM\PersistentCollection 
    * 
    * @ORM\OneToMany(targetEntity="Application\Entity\SiteCountries", cascade="persist", mappedBy="site") 
    */ 
    private $siteCountries; 

    /** 
    * @var \Doctrine\ORM\PersistentCollection 
    * 
    * @ORM\OneToMany(targetEntity="Application\Entity\SiteShippingMethods", cascade="persist", mappedBy="site") 
    */ 
    private $shippingMethods; 

    /** 
    * @var \Doctrine\ORM\PersistentCollection 
    * 
    * @ORM\OneToMany(targetEntity="Application\Entity\SitePaymentMethods", cascade="persist", mappedBy="site") 
    */ 
    private $sitePaymentMethods; 

    /** 
    * @var \Application\Entity\SiteModes 
    * 
    * @ORM\ManyToOne(targetEntity="Application\Entity\SiteModes") 
    * @ORM\JoinColumns({ 
    * @ORM\JoinColumn(name="site_mode_id", referencedColumnName="site_mode_id") 
    * }) 
    */ 
    private $siteMode; 

    /** 
    * 
    * @var integer 
    * @ORM\Column(name="payment_days", type="integer", nullable=false) 
    */ 
    private $paymentDays; 

    /** 
    * 
    * @var integer 
    * @ORM\Column(name="products_per_page", type="integer", nullable=false) 
    */ 
    private $productsPerPage; 

    /** 
    * @var \Doctrine\ORM\PersistentCollection 
    * 
    * @ORM\OneToMany(targetEntity="Application\Entity\Invoices", mappedBy="site") 
    * }) 
    */ 
    private $invoices; 

    public function __construct() 
    { 
     $this->categories = new ArrayCollection(); 
     $this->siteCountries = new ArrayCollection(); 
     $this->shippingMethods = new ArrayCollection(); 
     $this->vatRate = NULL; 
     $this->sitePaymentMethods = new ArrayCollection(); 
     $this->invoices = new ArrayCollection(); 
     $this->productsPerPage = 15; 
    } 

    .... Getters & Setters 

    /** 
    * @ORM\PrePersist 
    * @return \Application\Entity\Users 
    */ 
    public function prePersist() 
    { 
     $this->dateCreated = $this->getCurrentDateTime(); 
     $this->dateModified = $this->getCurrentDateTime(); 
     $this->currencyCode = $this->strToUpper($this->currencyCode); 
     $this->createdBy = $this->getAuthUser(); 
     return $this; 
    } 

    /** 
    * @ORM\PreUpdate 
    * @return \Application\Entity\Users 
    */ 
    public function preUpdate() 
    { 
     $this->dateModified = $this->getCurrentDateTime(); 
     $this->currencyCode = $this->strToUpper($this->currencyCode); 
     return $this; 
    } 
+0

這是因爲該名稱被視爲一個SQL關鍵字瞭解更多關於此in chapter 4.5. Identifiers/Primary Keys。嘗試在字符串'name =「\'PRIMARY \'''' – 0x13a

+0

周圍添加反引號感謝您的回覆。我曾嘗試反駁主要沒有運氣,仍然得到相同的錯誤。 – Garry

+0

bcz名字PRIMARY是一個MYSQL RESERVED關鍵字,呃你的錯誤有你的答案 –

回答

0

您已經標示在site_id列作爲主列當您添加註釋@ORM\Id$siteId財產。這是沒有必要添加如下一行:

@ORM\Index(name="PRIMARY", columns={"site_id"}), 

刪除了這一行,你會看到site_id列將在數據庫中自動索引正確的PRIMARY指數。

學說文檔

+0

我已經刪除了行'* @ORM \ Index(name =「PRIMARY」,columns = {「site_id」}),'並且仍然收到相同的錯誤。 – Garry

+0

@Garry你能展示你的完整實體定義嗎? – Wilt

+0

添加實體定義以根據請求進行提問。 – Garry

相關問題