ago*_*dev 9 php doctrine symfony doctrine-orm
我将学说与symfony结合使用。对于数据库设置,我使用注释。我成功创建了一个表,但是integer为city我需要更改为的字段提供了错误的格式string。我的理解是,当我更改客户类中的注释时,
class Customer{
/**
* @ORM\Column(type="integer", nullable=true)
* @var string city
*/
private $city;
}
Run Code Online (Sandbox Code Playgroud)
至
class Customer{
/**
* @ORM\Column(nullable=true)
* @var string city
*/
private $city;
}
Run Code Online (Sandbox Code Playgroud)
然后运行
php bin/console doctrine:migrations:diff
Run Code Online (Sandbox Code Playgroud)
映射的所有更改都应被识别,并且应生成包含ALTER TABLE查询或类似查询的php文件。但是,此命令答复为“未在映射信息中检测到更改”。我想念什么?
您应该将注释添加@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;
}
Run Code Online (Sandbox Code Playgroud)
您还可以使用此命令自动生成具有不同所需注释的实体:
bin/console doctrine:generate:entity
Run Code Online (Sandbox Code Playgroud)
当您的映射无效时,也会发生这种情况。
一个快速的解决方法是做
php bin/console doctrine:schema:validate
然后修复错误直到你看到
[OK] The mapping files are correct.
现在php bin/console doctrine:migrations:diff再次制作,它应该可以工作。