原csdn地址https://blog.cs|

蜗牛使劲冲

园龄:7年6个月粉丝:3关注:10

📂yii2
2018-09-02 16:57阅读: 8评论: 0推荐: 0

yii2数据迁移migrate

参考:https://blog.csdn.net/gao_yu_long/article/details/51742082
首先,到有yii.bat的根目录执行命令(注意要是dos命令框)

.\yii migrate/create paper

随后在console/migrations/m180902_080020_paper.php这样个文件,这是我来生成表的类,然后在改变下他继承的Migration,再改写这个方法

  public function up()
    {
        $this->createTable('paper', array_merge([
            'id' => $this->primaryKey(),
            'title' => $this->string()->notNull()->comment('标题'),
            'url' => $this->text()->notNull()->comment('图片地址'),
            'type' => $this->integer()->notNull()->defaultValue(0)->comment('大类型'),
            'kind' => $this->integer()->notNull()->defaultValue(0)->comment('中类型'),
            'introduction' => $this->string()->comment('简介'),
            'praise' => $this->integer()->comment('点赞数'),
            'view' => $this->integer()->comment('浏览量'),
        ], $this->commonColumns([
            'status', 'created_at', 'created_by', 'updated_at', 'updated_by'
        ])// 注意这边的分隔
        ), $this->setTableComment('壁纸主表'));

    }
    /*
    // 删除表 的一条和一整张表(注释这个)
       public function down()
       {
           echo "m180902_080020_paper cannot be reverted.\n";

           return false;
       }
       *

然后在执行命令

.\yii migrate m180902_080020_paper

这样表就生成了,同时在表migration记录了,如果想再执行一次得删掉这个记录。

本文作者:蜗牛使劲冲

本文链接:https://www.cnblogs.com/warrenwt/p/18074649

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   蜗牛使劲冲  阅读(8)  评论(0编辑  收藏  举报  
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起