# Yii Migrations ## Yii migration column types - `pk`: an auto-incremental primary key type, will be converted into “int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY” - `string`: will be converted into `varchar(255)` - `text`: will be converted into `text` - `integer`: will be converted into `int(11)` - `boolean`: will be converted into `tinyint(1)` - `float`: will be converted into `float` - `decimal`: will be converted into `decimal` - `datetime`: will be converted into `datetime` - `timestamp`: will be converted into `timestamp` - `time`: will be converted into `time` - `date`: will be converted into `date` - `binary`: will be converted into `blob` ## Examples of migration commands Contents of migration `protected\migrations\m200428_054554_create_claims_import_calls.php`: ```php class m200428_054554_create_claims_import_calls extends CDbMigration { const TABLE = 'claims_import_calls'; public function up() { $this->createTable(self::TABLE, [ 'id' => 'INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT', 'call_center_id' => "INT(11) UNSIGNED NOT NULL COMMENT 'ID in call_centers table'", 'crm_status' => "ENUM ('', 'E0004', 'E0005', 'E0006') NOT NULL COMMENT 'Status code in CRM'", 'call_result_id' => "INT(11) UNSIGNED COMMENT 'ID in call_results table'", 'call_started_at' => "TIMESTAMP NOT NULL COMMENT 'Call start time'", 'call_finished_at' => "TIMESTAMP NOT NULL COMMENT 'Call finished time'", 'cost' => "DECIMAL(6,2) COMMENT 'Cost of the call'", 'create_time' => 'TIMESTAMP NOT NULL DEFAULT NOW()', 'update_time' => 'TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW()', ] ); $this->execute('set FOREIGN_KEY_CHECKS=0;'); $this->addForeignKey('fk_claims_import_calls_call_result_id', self::TABLE, 'call_result_id', 'call_results', 'id', 'CASCADE', 'CASCADE' ); $this->execute('set FOREIGN_KEY_CHECKS=1;'); } public function down() { $this->dropForeignKey('fk_claims_import_calls_call_center_id', self::TABLE); $this->dropForeignKey('fk_claims_import_calls_call_result_id', self::TABLE); $this->dropTable(self::TABLE); } } ```