从Yii或Laravel的现有数据库中生成迁移。[英] Generating migration from existing databse in Yii or Laravel

本文是小编为大家收集整理的关于从Yii或Laravel的现有数据库中生成迁移。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在开发一个具有相当复杂的数据库(150+表)的项目.为了能够保持更改,我决定添加迁移,最好使用Yii或Laravel.



有人知道,如果可以生成初始从现有数据库迁移?



手动创建:







如果没有办法,任何人都知道一个好的基于PHP的框架,支持这样的功能?


推荐答案




  1. 将您的数据库连接设置添加到 protected / config / console.php p>


  2. 执行 yiic migrate create initial 以创建迁移的存根代码.


  3. 此要点的内容复制到 protected / commands / InitialDbMigrationCommand.php


  4. 执行 yiic initialdbmigration'name_of_your_database' initial_migration.php 生成 up()和 down()


  5. 复制并粘贴 up()和 code>方法从 initial_migration.php 到在 protected / migrations 文件夹中创建的文件.



本文地址:https://www.itbaoku.cn/post/597463.html

问题描述

I'm working on a project that has a fairly complex database (150+ tables). In order to be able to maintain changes, I've decided to add migrations, preferably using Yii or Laravel.

Does anybody know, if it is possible to generate a initial migration from an existing database?

Creating it by hand would:

  • take for ever and
  • be very error-prone.

If there is no way, does anybody know a good PHP-based framework, that supports such functionality?

推荐答案

Instructions for accomplishing this in Yii:

  1. Add your database connection settings to protected/config/console.php.

  2. Run yiic migrate create initial to create the stub code for the migration.

  3. Copy contents of this gist to protected/commands/InitialDbMigrationCommand.php.

  4. Run yiic initialdbmigration 'name_of_your_database' > initial_migration.php to generate up() and down() methods for initial database migration.

  5. Copy and paste up() and down() methods from initial_migration.php to the file created in the protected/migrations folder in step 2.