تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
6 الردود
17795 أدوات العرض

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
أبريل 21
4
1
أبريل 24
1842
1
يوليو 24
3414
0
فبراير 23
15
0
أغسطس 22
1623