美文网首页
2019-07-24-Yii-Framework-数据库迁移文件

2019-07-24-Yii-Framework-数据库迁移文件

作者: xiaojianxu | 来源:发表于2019-07-25 09:51 被阅读0次

    1 执行生成创建迁移文件,要注意迁移文件的命名。

    迁移文件名规范: create_tableName_table。

    执行命令 yii migrate/create create_tableName_table
    只有符合文件名规范,迁移文件才会生成 safedown 方法。
    回退迁移操作,执行 yii migrate/down。


    2 数据库迁移文件,创建表的规范语句。

    注释,数据类型与限制在同一条语句

     $this->createTable('{{%common_role}}', [
                'user_id' => $this->integer()->notNull()->unique()->comment('用户id'),
                'department' => $this->integer()->notNull()->comment('所属部门'),
                'role' => $this->tinyInteger()->notNull()->comment('角色等级')
            ]);
    

    相关文章

      网友评论

          本文标题:2019-07-24-Yii-Framework-数据库迁移文件

          本文链接:https://www.haomeiwen.com/subject/fedfrctx.html