Roby Sottini
Roby Sottini

Reputation: 2265

“Error 42P01: relation does not exist” (non public schema in PostgreSQL)

I want to create a foreign key but I got Error 42P01: relation solicitantes does not exist.

I have to schemas: public and laboratorio.

My table is called procedencias. I want to create a foreign key to solicitantes table. Both belongs to laboratorio schema. Even the autocomplete of the target table field works and find the table.

I see that:

enter image description here

I am using Jetbrains DataGrip software.

This is the DDL of the table called "solicitantes":

CREATE TABLE laboratorio.solicitantes
(
  id_solicitante serial NOT NULL,
  nombre_solicitante character varying(100) NOT NULL,
  CONSTRAINT solicitantes_pkey PRIMARY KEY (id_solicitante)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE laboratorio.solicitantes
  OWNER TO roby;

CREATE UNIQUE INDEX solicitantes_id_solicitante_uindex
  ON laboratorio.solicitantes
  USING btree
  (id_solicitante);

CREATE UNIQUE INDEX solicitantes_nombre_solicitante_uindex
  ON laboratorio.solicitantes
  USING btree
  (nombre_solicitante COLLATE pg_catalog."default");

I think I have to specify the schema name but I don't know where to do it in DataGrip.

Upvotes: 1

Views: 11324

Answers (2)

grimprophecy
grimprophecy

Reputation: 26

I had the same issue with adding foreign keys to a table in a custom schema from the modify table window. Adding schema to the "Target table" field did not work either. Instead I selected "Open in editor" rather than "Execute in database" and added the schema to the table name in the generated statement and it ran fine.

Upvotes: 1

Deiwys
Deiwys

Reputation: 13

have you tried to add the explicit schema to the table solicitantes?

Upvotes: 1

Related Questions