Php Laravel迁移:回滚添加和删除表列

Php Laravel迁移:回滚添加和删除表列,php,laravel,laravel-4,migration,database-migration,Php,Laravel,Laravel 4,Migration,Database Migration,我使用了php artisan migrate:make add_something_to_to_user_table--table=users 和编码 Schema::table('users', function(Blueprint $table) { $table->string('description1'); $table->string('description2'); $table->string('desc

我使用了php artisan migrate:make add_something_to_to_user_table--table=users

和编码

Schema::table('users', function(Blueprint $table)
    {
        $table->string('description1');
        $table->string('description2');
        $table->string('description3');
    });
并添加了三个字段,并将
php-artisan-migrate
和字段存储到数据库中

还发现,
迁移表
更新为行
2014\u 11\u 05\u 145536\u将某物添加到用户表

现在,当我使用php artisan migrate时:回滚

迁移表中的
2014\u 11\u 05\u 145536\u将某物添加到用户表中
行丢失,但添加到用户表中的列保持不变


为什么不删除表中的字段呢?再次使用
php artisan migrate
时会导致错误…

在迁移过程中应该有一个
down()
方法,如下所示:

public function down()
{
    Schema::table('users', function($table)
    {
        $table->dropColumn(array('description1', 'description2', 'description3'));
    });
}
这将在回滚时调用,并负责删除迁移添加的列

添加down公共函数以在回滚时删除用户表


根据laravel 7+文档,当您需要同时删除多个列时,这也将起作用

public函数down(){
Schema::table('users',函数(Blueprint$table){
$table->dropColumn(['description1','description2','description3']);
});
}

您是否在迁移类中正确设置了
down()
方法?是否必须提及
down()
up()
函数中的所有列也在同一文件中?是的,它们应该在同一文件中。在迁移类中,
up
方法将应用更改,而
down
方法将撤消更改。请记住,如果您已经运行了
artisan migrate:rollback
命令,并且没有设置
down
方法,则必须在重新运行迁移之前手动删除列(这就是为什么您在尝试调用
migrate
时出错的原因,因为它试图在3列已经存在的情况下添加它们)。因此,如果我要删除一列,我必须在
up()
和add-in
down()中删除
是这样吗?完全正确。在
向上
中设置所需的更改,在
向下
中设置所需的更改。
public function down()
{
    Schema::drop('users');
}