Yii provides a set of migration command line tools that allow you to:
- create new migrations;
- apply migrations;
- revert migrations;
- re-apply migrations;
- show migration history and status.
All these tools are accessible through the command
yii migrate. In this section we will describe in detail how to accomplish various tasks using these tools. You may also get the usage of each tool via the help command
yii help migrate.
Add the package to your composer.json:
composer update or alternatively run
composer require bizley/migration
Add the following in your configuration file (preferably console configuration file):
'components' => [
'controllerMap' => [
'migration' => [
'class' => 'bizley\migration\controllers\MigrationController',
Run console command
php yii migration <table_name>
to create migration for DB table .
You can create multiple migrations for many tables at once:
php yii migration <table_name1>,<table_name2>,<table_name3>
–migrationPath (default ‘@app/migrations’) Directory storing the migration classes.
–templateFile (default ‘@vendor/bizley/migration/src/views/migration.php’) Template file for generating new migrations.
–useTablePrefix (default true) Whether the table names generated should consider the
tablePrefix setting of the DB connection.
–db (default ‘db’) Connection|array|string the DB connection object or the application component ID of the DB connection to use when creating migrations.