更新时间:2023-12-01 09:13:46
将您的数据库连接设置添加到 protected / config / console.php
p>
执行 yiic migrate create initial
以创建迁移的存根代码。
将此要点的内容复制到 protected / commands / InitialDbMigrationCommand.php
执行 yiic initialdbmigration'name_of_your_database' initial_migration.php
生成 up()
和 down()
复制并粘贴 up()
和 code>方法从
initial_migration.php
到在 protected / migrations
文件夹中创建的文件。
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:
If there is no way, does anybody know a good PHP-based framework, that supports such functionality?
Instructions for accomplishing this in Yii:
Add your database connection settings to protected/config/console.php
.
Run yiic migrate create initial
to create the stub code for the migration.
Copy contents of this gist to protected/commands/InitialDbMigrationCommand.php
.
Run yiic initialdbmigration 'name_of_your_database' > initial_migration.php
to generate up()
and down()
methods for initial database migration.
Copy and paste up()
and down()
methods from initial_migration.php
to the file created in the protected/migrations
folder in step 2.