我可以在Codeigniter中创建和运行迁移,但无法回滚迁移。有人能帮助我如何在Codeigniter中回滚迁移吗?
使用Illuminate\数据库\胶囊\管理器作为胶囊;
类迁移创建语言扩展配置项迁移{
public function up() {
Capsule::schema()->create('languages', function($table){
$table->increments('id');
$table->string('name', 120);
$table->string('country', 120);
$table->string('country_code', 20);
$table->enum('status', array('0','1'))->default('0');
$table->timestamps();
});
}
/*
* Sample function for rolling back the above action
*/
public function down()
{
Capsule::schema()->drop('languages');
}
}
2条答案
按热度按时间puruo6ea1#
你能发布你的移民代码吗?
在每个迁移中都有一个名为
down
的方法,这就是向下迁移时执行的方法。确保你的sql语句处于down状态,例如,销毁一个表。然后,加载你想要的迁移版本。kkbh8khc2#
对于Codeigniter 4,正确答案是:
注传递给
regress()
的参数是一个批处理ID,可以在迁移表中找到。这也是要回退的版本-即,如果最新批处理为3,则将丢失批处理2和3。