eloquent - 在 laravel 中删除包时从表中删除列
问题描述
通过安装包添加数据库中的字段时,如何确保在卸载包时将其删除。会被删除吗?
解决方案
许多 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
随包附带的文件,查看创建的内容并将其与您在数据库中看到的表/列进行比较。
推荐阅读
- angular - Bootstrap 下拉菜单在 Angular 中不起作用
- docker - 如何将文件复制到 docker 映像?
- python - Python Reduce:参数顺序导致错误
- php - file_get_contents(https://www.google.com/recaptcha/api/siteverify):无法打开流:在 laravel 项目中
- sql - SQL:年份为零的最小日期
- api - 是否可以通过 API 在创建日期之前删除 Nexus 存储库上的 docker 图像?
- javascript - 为什么 module.export 设置多次?
- dependencies - 使用 Yarn 2 使依赖项的依赖项可用
- xamarin - 如何检查用户是否有权查看 Xamarin.Forms 中的页面
- node.js - 安装 ursa 时出错 - 错误 C2660:'v8::String::Utf8Length':函数不接受 0 个参数