How to create your own feature migration in yii2

This is the default code for migration

<?php

use yii\db\Schema;
use yii\db\Migration;

class m150101_185401_create_news_table extends Migration
{
    public function up()
    {
        $this->createTable('news', [
            'id' => Schema::TYPE_PK,
            'title' => Schema::TYPE_STRING . ' NOT NULL',
            'content' => Schema::TYPE_TEXT,
        ]);
    }

    public function down()
    {
        $this->dropTable('news');
    }
}

here TYPE_TEXT is a predefined attribute, since I can create my own trait, for example int (11) Not NULL, unsigned unsignedInt, there is a way to create my own traits.

+4
source share
1 answer

To do this, you can define your personal SchemaBuilderTraits in the correct namespace and remember this in your code

look at this yii2 document http://www.yiiframework.com/doc-2.0/yii-db-schemabuildertrait.html

https://github.com/yiisoft/yii2/blob/master/framework/db/Migration.php

In Migration.php, you can easily view the call to use in the first line.

yii\db\SchemaBuilderTrait . 2.0.6.

+2

Source: https://habr.com/ru/post/1613237/


All Articles