lav45/yii2-db-migrate
Composer 安装命令:
composer require lav45/yii2-db-migrate
包简介
This extension allows you to easily create large migrations associated with many foreign keys.
关键字:
README 文档
README
Это расширение поможет вам избежать конфликтов в вашей SQL db при создании foreign key.
Установка расширения
~$ composer require --prefer-dist lav45/yii2-db-migrate
Подключение
use lav45\db\MainMigration; class m000000_000000_init extends MainMigration { // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci public $defaultTableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; public function table_news() { $this->createTable('news', [ 'id' => $this->primaryKey(), 'author_id' => $this->integer()->notNull(), // ... ]); $this->addForeignKey('news', 'author_id', 'user', 'id', 'SET NULL'); } public function table_news_tag() { $this->createTable('news_tag', [ 'news_id' => $this->integer()->notNull(), 'tag_id' => $this->integer()->notNull(), ]); $this->addPrimaryKey('news_tag', ['news_id', 'tag_id']); $this->addForeignKey('news_tag', 'news_id', 'news', 'id'); $this->addForeignKey('news_tag', 'tag_id', 'tag', 'id'); } public function table_tag() { $this->createTable('tag', [ 'id' => $this->primaryKey(), // ... ]); } public function table_user() { $this->createTable('user', [ 'id' => $this->primaryKey(), // ... ]); } }
~$ php yii migrate/up Yii Migration Tool (based on Yii v2.0.7-dev) Creating migration history table "migration"...Done. Total 1 new migrations to be applied: m000000_000000_init *** applying m000000_000000_init > create table user ... done (time: 0.072s) > create table news ... done (time: 0.064s) > add foreign key news_author_id_fkey: news (author_id) references user (id) ... done (time: 0.001s) > create table news_tag ... done (time: 0.001s) > add primary key news_tag_pk on news_tag (news_id,tag_id) ... done (time: 0.086s) > add foreign key news_tag_news_id_fkey: news_tag (news_id) references news (id) ... done (time: 0.001s) > create table tag ... done (time: 0.066s) > add foreign key news_tag_tag_id_fkey: news_tag (tag_id) references tag (id) ... done (time: 0.001s) *** applied m000000_000000_init (time: 0.292s) 1 migrations were applied. Migrated up successfully.
统计信息
- 总下载量: 17.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-05-21