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 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步