Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
17804 มุมมอง

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.




อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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);
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง

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

คำตอบที่ดีที่สุด

hello ,  see below answers i hope will help you :

https://stackoverflow.com/questions/11966420/what-is-causing-error-there-is-no-unique-constraint-matching-given-keys-for-ref

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

see This https://bugs.launchpad.net/openobject-server/+bug/897098

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
เม.ย. 21
4
1
เม.ย. 24
1843
1
ก.ค. 24
3417
0
ก.พ. 23
15
0
ส.ค. 22
1624