简体   繁体   English

数据库包含点(。)值时的跨数据库外键问题

[英]Cross-database foreign key issue when database contains a dot(.) value

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"我在 laravel 迁移中面临跨数据库关系分配的问题,因为我的数据库名称包含一个点(。)值,我的数据库名称是 =“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 MariaDB 服务器版本,用于在 '.`com``.`users` (`id`) 附近使用的正确语法在删除 RESTRICT 时更新 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');
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM