I am facing an issue to assign across cross-databases relationship in laravel migration because my database name contains a dot(.) value, My Database name is = "demo.local.com"
Schema::table('user_details', function(Blueprint $table)
{
$table->foreign('user_id')->references('id')
->on('`demo.local.com`.users')
->onUpdate('RESTRICT')->onDelete('RESTRICT');
});
I am using that way but its return error like
MariaDB server version for the right syntax to use near '.`com```.`users` (`id`) on delete RESTRICT on update RESTRICT
So it's possible to assign a foreign key when the database name contains a dot(.) value?
I have found the solution by using DB raw query and it's working for me
Schema::table('user_details', function(Blueprint $table)
{
$table->foreign('user_id')->references('id')
->on(\DB::raw('`demo.local.com`.users'))
->onUpdate('RESTRICT')->onDelete('RESTRICT');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.