php - 如何将 DoctrineMigrationsBundle 与 yaml 文件一起使用?
问题描述
当我像上面的示例一样使用 Doctrine Annotation 文件时,该命令php bin/console doctrine:migrations:diff
可以完美运行。
#src/Entity/User.php
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity(repositoryClass="Repository\UserRepository")
* @ORM\Table(
* schema="data",
* name="ts_user",
* options={"comment":"Utilisateurs de l'application"},
* uniqueConstraints={@ORM\UniqueConstraint(name="uk_usr_email", columns={"usr_email"})}
* )
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="usr_id")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true, name="usr_name")
*/
private $name;
/**
* @ORM\Column(type="text", nullable=false, name="usr_email")
*/
private $email;
/**
* @ORM\Column(type="text", nullable=true, name="usr_password")
*/
private $password;
}
由于某些原因(特征、接口),我必须使用学说 yaml 文件来声明我的实体。一旦我用 yaml 文件替换注释,迁移命令就会抛出此错误:
在 OrmSchemaProvider.php 第 41 行:
没有要处理的映射信息
这是我的 yaml 文件:
#src/Resources/config/doctrine/User.orm.yml
App\Entity\User:
type: entity
schema: data
table: ts_user
repositoryClass: Repository\UserRepository
id:
id:
type: integer
column: usr_id
generator:
strategy: AUTO
fields:
name:
type: text
nullable: true
column: usr_name
email:
type: text
nullable: false
column: usr_email
password:
type: text
nullable: true
column: usr_password
uniqueConstraints:
uk_usr_email:
columns: [usr_email]
options:
comment: Utilisateurs de l'application
由于这个错误,我认为它没有找到我的 yaml 文件。它在错误的目录中吗?把这个文件放在哪里?我在源代码中没有看到任何声明我的 yaml 文件目录的内容。我已经在这个目录中尝试过但没有成功:
- 源/实体
- src/资源/config/doctrine/
- src/Resources/config/doctrine/App
- src/Resources/config/doctrine/App/Entity
- src/Resources/config/doctrine/Entity
我究竟做错了什么?
环境:PHP 7.2.3,Symfony 4.1.1(内核:src,环境:开发,调试:真)
解决方案
如果自动映射与 Doctrine 一起使用,您将必须检查您的 orm 配置并将其设置为使用 yml 加载这些实体
就像是:
doctrine:
# ...
orm:
# ...
auto_mapping: true
mappings:
# ...
AppBundle:
type: yml
dir: SomeResources/config/doctrine
有关更多信息,您可以查看 Symfony 教程中 Doctrine 配置的自定义映射部分
https://symfony.com/doc/3.4/reference/configuration/doctrine.html
推荐阅读
- r - R:突出显示数据表中的一行的问题
- c++ - 尽管主机、方法、内容类型设置正确,但 Poco 库 PUT 方法未按预期工作
- java - 使用 ArrayList 和 java 处理异常
- javascript - ChartJS AJAX Javascript
- html - 元素的锚点重定向到基于 IIS 的动态页面上的主页
- python - 使用编码的谷歌身份验证文件从 python 运行大查询
- spring-data-jpa - Spring Webflux(Reactor)调度程序在错误后不会终止
- android - 如何从非上下文类安全地调用意图服务?
- c# - Dynamics CRM 中的 CalculatePrice 消息
- webpack - 如何使用 babel 和 webpack 进行动态代码拆分?