Php 原则:迁移:差异给予”;在您的映射信息中未检测到任何更改”;

Php 原则:迁移:差异给予”;在您的映射信息中未检测到任何更改”;,php,symfony,doctrine-orm,doctrine,Php,Symfony,Doctrine Orm,Doctrine,我把条令和symfony结合起来使用。对于数据库设置,我使用注释。我成功创建了一个表,但为需要更改为string的字段city提供了错误的格式integer。我的理解是,当我将customers类中的注释从 class Customer{ /** * @ORM\Column(type="integer", nullable=true) * @var string city */ private $city; } 到 然后跑 php bin/console doct

我把条令和symfony结合起来使用。对于数据库设置,我使用注释。我成功创建了一个表,但为需要更改为
string
的字段
city
提供了错误的格式
integer
。我的理解是,当我将customers类中的注释从

class Customer{

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

}

然后跑

php bin/console doctrine:migrations:diff

应识别映射的所有更改,并生成包含ALTER TABLE查询或类似查询的php文件。但是,此命令的回复是“未检测到映射信息中的任何更改”。我缺少什么?

我需要先用

php bin/console doctrine:cache:clear-metadata 

成功

您应该将注释
@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;

}

如果您使用的是复杂的Symfony配置,请检查
doctor.orm.entity\u managers.default.mappings
config.yml中的配置值。当它不工作时,您可能必须在这里添加新的捆绑包

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

一个快速的解决方法是

php bin/console原则:schema:validate

然后修复错误,直到看到

[确定]映射文件正确。


现在再做一次php bin/console原则:migrations:diff,它应该可以工作。

如果它可以帮助其他人,对我来说,这只是在我的实体类中设置了一个错误的名称空间的问题


我从另一个包复制了一个实体,但忘记了更新名称空间。

我的问题是,我已将实体放在文件夹中,但必须将其放在实体文件夹中。

@ORM\Column(type=“string”)type string是默认值。但是,我尝试了您的建议,但行为保持不变。对不起,我未能给出完整的代码。当然,在我的代码中有实体注释。
<?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