首页 > 解决方案 > 在 laravel 中删除包时从表中删除列

问题描述

通过安装包添加数据库中的字段时,如何确保在卸载包时将其删除。会被删除吗?

标签: eloquentcomposer-phplaravel-5.7

解决方案


许多 Laravel 包都带有像这样创建表(有时还包括字段)的迁移:

public function up()
{
    Schema::create($this->getTableName(), function (Blueprint $table) {
        $table->increments('id');
        $table->string('first_name');
        $table->string('last_name');
        $table->string('email');
        $table->timestamps();
    });
}

通常,在拆卸时将它们移除

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists($this->getTableName());
}

但是,有时会出现问题,您可能需要检查自己。请参阅database/migrations随包附带的文件,查看创建的内容并将其与您在数据库中看到的表/列进行比较。


推荐阅读