原文地址 http://www.yiichina.com/topic/6571
YII使用migrate命令创建表,只需三步:
1、在yii批处理文件所在目录下执行
$ yii migrate/create init_services_table
2、执行完成后,会在console/migrations目录下生成名为*init_services_table.php的文件
修改文件
<?php
use yiidbMigration;
class m160904_145401_init_services_table extends Migration
{
public function up()
{
$this -> createTable(
'service',
[
'id' => 'pk',
'name' => 'string unique',
'hourly_rate' => 'integer',
]
);
}
public function down()
{
#echo "m160904_145401_init_services_table cannot be reverted.n";
#return false;
$this -> dropTable('service');
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
3、执行migration命令,会在对应数据库中创建该表。
yii migrate