php - Laravel Postgres 多模式数据库迁移
问题描述
我正在使用 Postgres 和 Laravel 5.8。我的数据库有多个模式。每个模式都有一个patients
表。我通过在现有患者表中添加密码列来为每个模式中的患者创建身份验证。迁移遍历每个模式,如果密码列不存在,则应添加它。迁移在我的控制台和迁移表中成功创建,但在数据库表中没有。我已经尝试了几次,但仍然没有。任何关于我可能做错的建议将不胜感激。
移民
class UpdatePatientsAuthentication extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$facilities = Facility::all();
foreach ($facilities as $facility) {
$search_path = $facility['schema_name'];
DB::statement("SET search_path = $search_path");
if (Schema::hasTable('patients')) {
Schema::table('patients', function (Blueprint $table) {
$table->string('password')->nullable();
});
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$table->dropColumn('password');
}
}
解决方案
推荐阅读
- kotlin - Gradle - 尽管有大量内存,但运行测试时出现 OutOfMemoryError
- heroku - 请问我该如何解决这个问题?
- python - 如何在python中查看对等方的ssl证书
- excel - 选择时更改形状文本颜色
- angular - Angular 11在两个不相关的组件之间传递数据不起作用
- node.js - docker-compose:无法将本地模块添加到项目中,找不到 package.json 文件
- javascript - 当我尝试使用一个命令添加 2 个或更多角色时,它会删除它们
- html - 偏移 html 锚以调整固定标题 - Safari 上的不同 CSS
- angular - 将路由参数转换为可为空的数字
- postgresql - 插入操作不锁定 typeorm (postgresql)