Ir al contenido
Menú
Se marcó esta pregunta
6 Respuestas
17775 Vistas

Error : psycopg2.errors.InvalidForeignKey: there is no unique constraint matching given keys for referenced table "res_users"

occurred after restored database of odoo12 enterprise version.




Avatar
Descartar
Mejor respuesta

Connect to PostgreSQL database using terminal with odoo as user. Then select your odoo database with

\c YOUR_ODOO_DATABASE_NAME

command and then run the below sql command,

alter table res_users add primary key (id);
Avatar
Descartar
Mejor respuesta

psycopg2.errors.InvalidForeignKey: there is no unique constraint matching given keys for referenced table "res_users" answer its becuase of odoo conf soft and hard limits i resolve this issue by increase limit_memory_hard = 9999999999 limit_memory_soft = 9999999999 limit_request = 8192 limit_time_cpu = 1200 limit_time_real = 1200

Avatar
Descartar
Mejor respuesta

I had the same issue after restored a database

my env : odoo v15 enterprise version with postgresql v14

i used the answer of rafiul but i found that the is more than one hundred table with missing primary key after restored.

So after found this answer https://stackoverflow.com/questions/60523568/add-primary-key-to-all-tables-in-database-that-dont-have-one-yet , i customized the command to have this one. You can use it in case you want to set the column id as a primary key for all table where primary key is missing.

DO $$
DECLARE row RECORD;
BEGIN
FOR row IN
SELECT tab.table_schema, tab.table_name
FROM information_schema.tables tab
LEFT JOIN information_schema.table_constraints tco
ON tab.table_schema = tco.table_schema
AND tab.table_name = tco.table_name
AND tco.constraint_type = 'PRIMARY KEY'
WHERE tab.table_type = 'BASE TABLE'
AND tab.table_schema not in ('pg_catalog', 'information_schema')
AND tco.constraint_name is null
AND tab.table_name in (SELECT table_name FROM information_schema.columns WHERE column_name = 'id')
ORDER BY table_schema, table_name
LOOP
EXECUTE 'ALTER TABLE "' || row.table_schema || '"."' || row.table_name || '" ADD CONSTRAINT PK_' || row.table_name || ' PRIMARY KEY (ID)';
END LOOP;
END;
$$;

YOU CAN RUN IT IN PGADMIN



Avatar
Descartar
Mejor respuesta

did you find any solution 
if you have, please tell me how to fix it

Avatar
Descartar

yes
psycopg2.errors.InvalidForeignKey: there is no unique constraint matching given keys for referenced table "res_users" answer its becuase of odoo conf soft and hard limits
i resolve this issue by increase
limit_memory_hard = 9999999999
limit_memory_soft = 9999999999
limit_request = 8192
limit_time_cpu = 1200
limit_time_real = 1200

most of this problem comes after restoring db. but do not entirely restore

Publicaciones relacionadas Respuestas Vistas Actividad
0
abr 21
4
1
abr 24
1835
1
jul 24
3409
0
feb 23
15
0
ago 22
1620