doctrine:migrations:diff给出“在您的映射信息中未检测到更改”

问题描述 投票:8回答:4

我将学说与symfony结合使用。对于数据库设置,我使用注释。我成功创建了一个表,但是为字段integer设置了错误的格式city,我需要将其更改为string。我的理解是,当我从[

更改[客户]类中的注释时
class Customer{

  /**
   * @ORM\Column(type="integer", nullable=true)
   * @var string city
   */
  private $city;

}

class Customer{

  /**
   * @ORM\Column(nullable=true)
   * @var string city
   */
  private $city;

}

然后运行

php bin/console doctrine:migrations:diff

应该识别所有映射更改,并且应生成包含ALTER TABLE查询或类似查询的php文件。但是,此命令以“”未在映射信息中检测到更改“答复。我想念什么?

php symfony doctrine-orm doctrine
4个回答
8
投票

我需要先使用以下命令清除缓存

php bin/console doctrine:cache:clear-metadata 

成功!


4
投票

您应将注释@Entity添加到要在准则ORM中识别为实体的实体。

<?php

/**
 * Customer
 *
 * @ORM\Table(name="customers")
 * @ORM\Entity(repositoryClass="YourBundle/Repository/YourRepositoryName")
 */
class Customer{

       /**
        * @ORM\Column(type="string", nullable=true)
        * @var string city
        */
        private $city;

}

您还可以使用此命令来自动生成带有不同必需注释的实体:

bin/console doctrine:generate:entity

4
投票

当映射无效时也会发生这种情况。

一个快速的解决方法是做

php bin/console doctrine:schema:validate

然后修复错误,直到看到为止

[OK] The mapping files are correct.

现在再次创建php bin/console doctrine:migrations:diff,它应该可以工作。


0
投票

如果使用复杂的Symfony配置,请检查doctrine.orm.entity_managers.default.mappings中的config.yml配置值。可能无法使用时,您必须在此处添加新的捆绑软件。

© www.soinside.com 2019 - 2024. All rights reserved.