首页 > 解决方案 > 使用 ORM 但没有 Symfony 的 Doctrine 2 迁移

问题描述

我构建了使用 Symfony 组件的应用程序,但只是少数。这意味着我不使用集成包。

我想使用教义。目前,我在将 Doctrine ORM 与 Doctrine 迁移集成时遇到问题。

我已经安装

"doctrine/migrations": "^1.8",
"doctrine/dbal": "^2.8",
"doctrine/orm": "^2.6",
"symfony/console": "^4.1"

和其他几个 Symfony 模块。但我不使用标准的 Symfony 配置目录。我已经配置好migrations.xmlmigrations-db.php

我在App\Infractructure\Entities.

示例实体

命名空间 Iaso\Entities;

/** @Entity */
class User
{
    /** @Id
    * @Column(type="integer")
    * @GeneratedValue
    */
    private $id;

    /** @Column(length=150) */
    private $email;

    /** @Column(length=255) */
    private $password;

    /** @Column(length=150, name="first_name") */
    private $firstName;

    /** @Column(length=150, name="last_name") */
    private $lastName;

    /** @Column(type="datetime", name="posted_at") */
    private $postedAt;

    /** @Column(type="datetime", name="updated_by") */
    private $updatedAt;

    /** @OneToOne(targetEntity="User")
    * @JoinColumn(name="updated_by", referencedColumnName="id")
    */
    private $updatedBy;

}

我可以创建一个空的迁移文件,我可以运行我手动创建的迁移。我想使用 ORM 和基于与当前数据库的实体差异的自动迁移。

我看到一些问题。

  1. 我在控制台命令 migrations:diff 中看不到,我不知道为什么
  2. 我确定我需要告诉迁移知道我的实体在哪里,但我不知道如何。我阅读了文档并尝试直接在命令中在 Doctrine GitHub 上找到一些东西。我找不到任何有趣的东西。

感谢您的任何提示。

标签: phpsymfonydoctrine-ormdoctrine

解决方案


推荐阅读