B
B
BonBon Slick2017-05-17 21:46:12
PostgreSQL
BonBon Slick, 2017-05-17 21:46:12

Laravel exists validation in PostgreSQL - ERROR - Feature not supported: 7 ERROR: cross-database references are not implemented?

Referral system to check if the user's nickname exists in the database:

'nickname' => 'required|string|unique:pgsql.public.users.nickname',
   'referral' => 'nullable|string|exists:pgsql.public.users.nickname',

Laravel 5.4
ERROR:
Illuminate \ Database \ QueryException (0A000)

SQLSTATE[0A000]: Feature not supported: 7 ERROR: cross-database references are not implemented: "public.users.nickname" LINE 1: select count(*) as aggregate from "public"."users"."nickname... ^ (SQL: select count(*) as aggregate from "public"."users"."nickname" where "referral" = BonBonSlick)

Tried like this:
'referral' => [
                'nullable',
                Rule::exists('users')->where(function ($query) {
                    $query->where('nickname', $this->referral);
                }),
            ],

Same error:
Illuminate \ Database \ QueryException (42703)
SQLSTATE[42703]: Undefined column: 7 ERROR: column "referral" does not exist LINE 1: select count(*) as aggregate from "users" where "referral" =... ^ (SQL: select count(*) as aggregate from "users" where "referral" = qwe and ("nickname" = qwe))

I need to check the referral by nickname, of course there is no such column...
What am I doing wrong, tell me please?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2017-05-17
@BonBonSlick

A query in postgresql cannot access other databases using the database_name.object syntax. Only to the one to which the connection was opened.
See where your tables are located, if within the same database, then how your framework builds the query and what needs to be written in order for the resulting query to be correct.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question