我将学说与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 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;
}
您还可以使用此命令来自动生成带有不同必需注释的实体:
bin/console doctrine:generate:entity
当映射无效时也会发生这种情况。
一个快速的解决方法是做
php bin/console doctrine:schema:validate
然后修复错误,直到看到为止
[OK] The mapping files are correct.
现在再次创建php bin/console doctrine:migrations:diff
,它应该可以工作。
如果使用复杂的Symfony配置,请检查doctrine.orm.entity_managers.default.mappings
中的config.yml
配置值。可能无法使用时,您必须在此处添加新的捆绑软件。