从Yii或Laravel中的现有数据库生成迁移 [英] Generating migration from existing database in Yii or 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:
-
将数据库连接设置添加到
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
复制并粘贴到步骤2中在protected/migrations
文件夹中创建的文件中.
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屋!