YII使用migrate命令创建表 [ 技术分享 ]
YII使用migrate命令创建表,只需三步: 1、在yii批处理文件所在目录下执行 $ yii migrate/create init_services_table 2、执行完成后,会在console/migrations目录下生成名为*init_services_table.php的文件 修改文件
<?php
use yii\db\Migration;
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
共 0 条回复
没有找到数据。
38514
            注册时间:2016-10-31
最后登录:1970-01-01
在线时长:0小时0分
    最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
 - 金钱45
 - 威望0
 - 积分45