arrow_back
Back

Yii2 database migrations: up, down, and console commands

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Columns

Adding a column:

$this->addColumn('job', 'score', $this->integer()->after('starred'));

Removing a column:

$this->dropColumn('job', 'score');

Index

We can name it like idx-TABLE_NAME-FIELD_NAME.

Add index:

$this->createIndex(
    'idx-post-category_id',
    'post',
    'category_id'
);

Delete index:

$this->dropIndex(
    'idx-post-category_id',
    'post'
);
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Yii2 testing: PHPUnit, Codeception, and test environments

arrow_forward