在 laravel 迁移中指定连接
Specify connection in a laravel migration
我正在为 Laravel 6 项目创建迁移。它具有多个数据库连接以确保数据安全。
我正在尝试使用 laravel 迁移来控制数据库和播种。为了在模型中清楚,我设置了两个定义在 config/database.php
中的数据库
'connections' => [
'core' => [ ... ],
'regional' => [ ... ]
]
然后使用 .env
文件填充这些内容。这似乎按预期工作。
开始迁移后,基本 laravel ...create_users_table.php
文件具有以下内容:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
如何指定它使用的数据库连接?
提前致谢。
尝试Schema::connection('core')->create...
在此处查看更多信息:https://laravel.com/docs/6.x/migrations
我正在为 Laravel 6 项目创建迁移。它具有多个数据库连接以确保数据安全。
我正在尝试使用 laravel 迁移来控制数据库和播种。为了在模型中清楚,我设置了两个定义在 config/database.php
'connections' => [
'core' => [ ... ],
'regional' => [ ... ]
]
然后使用 .env
文件填充这些内容。这似乎按预期工作。
开始迁移后,基本 laravel ...create_users_table.php
文件具有以下内容:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
如何指定它使用的数据库连接?
提前致谢。
尝试Schema::connection('core')->create...
在此处查看更多信息:https://laravel.com/docs/6.x/migrations