Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
17797 Lượt xem

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.




Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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);
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 21
4
1
thg 4 24
1843
1
thg 7 24
3415
0
thg 2 23
15
0
thg 8 22
1624