Doctrine中的额外changeColumn生成迁移差异 [英] Extra changeColumns in Doctrine generate-migrations-diff

查看:185
本文介绍了Doctrine中的额外changeColumn生成迁移差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的yaml模式文件之间生成迁移:即运行:

I'm generating migrations between different yaml schema files: i.e. running:

symfony doctrine:generate-migrations-diff

symfony doctrine:generate-migrations-diff

生成的迁移文件有一整个changeColumn调用,在上一个模式文件更改中未添加。

And the resulting migration file has a whole slew of changeColumn calls that weren't added in the last schema file change.

例如,如果运行generate-migrations-diff,而不用改变你的架构文件,你应该得到一个空的up()函数。但是,对我来说,这个函数对我的数据库中的每个表都有一个changeColumn调用。

For example, if you run generate-migrations-diff without changing your schema file whatsoever, you should get an empty up() function. However, the function that results for me has a changeColumn call for virtually every table in my database.

我做错了,这是一个bug?

Am i doing something wrong or is this a bug?

推荐答案

generate-migrations-diff不会区分两个不同的yaml文件。它实际上比较了您的模型和您的yaml文件,然后根据差异生成迁移。如果您从与yaml和classes同步的数据库开始,您的工作流程应该是:

The generate-migrations-diff doesn't diff two different yaml files. It actually compares your models and your yaml file and then generates a migration based on the differences. If you start from a db that is in sync with your yaml and classes, your workflow to make schema changes should be:


  1. 更改yaml文件

  2. generate-migrations-diff 以将您当前(更改)的yaml与您的(未更改)模型区分开来。这将在您的doctrine / migrations目录中生成一个迁移文件(或者您的doctrine配置中的任何migrations_path)。

  3. 迁移以运行创建的迁移步骤2并修改您的数据库

  4. generate-models-yaml 根据您的yaml文件生成新的类。这些去您已经指定生成的模型去(你的doctrine配置中的models_path)。

  5. 生成sql 来生成一个SQL文件。这将会在你的学说sql_path配置设置为。

  1. Change yaml file
  2. generate-migrations-diff to diff your current (changed) yaml with your (unchanged) models. This will generate a migrations file in your doctrine/migrations directory (or whatever migrations_path is set to in your doctrine config).
  3. migrate to run the migration created in step 2 and modify your database
  4. generate-models-yaml to generate new classes based on your yaml file. These go where you've specified your generated models go (models_path in your doctrine config).
  5. generate-sql to generate a SQL file. This will go where your doctrine sql_path config is set to.

这篇关于Doctrine中的额外changeColumn生成迁移差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆