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

查看:30
本文介绍了从 Yii 或 Laravel 中的现有数据库生成迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个具有相当复杂的数据库(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.

this gist 的内容复制到 protected/commands/InitialDbMigrationCommand.php.

Copy contents of this gist to 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.

initial_migration.php 中的 up()down() 方法复制并粘贴到 中创建的文件中>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.

这篇关于从 Yii 或 Laravel 中的现有数据库生成迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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