在 Yii 或 Laravel 中从现有数据库生成迁移

2022-01-04 00:00:00 database migration php laravel yii

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

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?

手工创建:

  • 永远和
  • 非常容易出错.

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

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

推荐答案

在 Yii 中完成此操作的说明:

Instructions for accomplishing this in Yii:

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

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

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

将本要点的内容复制到protected/commands/InitialDbMigrationCommand.php.

运行 yiic initialdbmigration 'name_of_your_database' >initial_migration.php 生成用于初始数据库迁移的 up()down() 方法.

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

up()down() 方法从 initial_migration.php 复制并粘贴到 中创建的文件中>protected/migrations 文件夹在第 2 步中.

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

相关文章