yii migrate的使用

来源:互联网 发布:软件效果器怎么用 编辑:程序博客网 时间:2024/05/20 21:46

原文地址    http://www.yiichina.com/topic/6571


YII使用migrate命令创建表,只需三步:
1、在yii批处理文件所在目录下执行
$ yii migrate/create init_services_table
2、执行完成后,会在console/migrations目录下生成名为*init_services_table.php的文件
修改文件

<?phpuse 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


原创粉丝点击