Created
October 26, 2016 15:38
-
-
Save mgerasimchuk/19329f2c22db61c58d9dfbea631441b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\db\Migration; | |
class m160209_063654_group_student__create_table extends Migration | |
{ | |
public function up() | |
{ | |
$this->createTable('{{%group_student}}', [ | |
'id' => $this->primaryKey(), | |
'groupId' => $this->integer()->notNull(), | |
'studentId' => $this->integer()->notNull(), | |
'createdAt' => $this->dateTime(), | |
'updatedAt' => $this->dateTime(), | |
]); | |
$this->addForeignKey('FK_group_student_groupId', '{{%group_student}}', 'groupId', '{{%group}}', 'id'); | |
$this->addForeignKey('FK_group_student_studentId', '{{%group_student}}', 'studentId', '{{%user_account}}', 'id'); | |
$this->createIndex('UK_group_student_groupId_studentId', '{{%group_student}}', ['groupId', 'studentId'], true); | |
} | |
public function down() | |
{ | |
$this->dropIndex('UK_group_student_groupId_studentId', '{{%group_student}}'); | |
$this->dropForeignKey('FK_group_student_studentId', '{{%group_student}}'); | |
$this->dropForeignKey('FK_group_student_groupId', '{{%group_student}}'); | |
$this->dropTable('{{%group_student}}'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment