Skip to Content
Menu
This question has been flagged
1 Reply
1280 Views

Hi all.


I have a database with Odoo 11 Enterprise On-premises. This database has lost primary key constraint in all tables. I have no idea how this is possible.


The error is this:

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

This is not only for res_groups, but for every table. If I go to the database and look for description of any table (for example: \d res_users), I can see that constraints are not present.


I saw a way to re-create primary keys but this doesn't solve the issue, because every foreign key refference has been lost too.


Does anyone have an idea of what could being happening and how to solve it?


Thank you in advance.

Avatar
Discard

you need to back your last backup as soon as possible

Author

Thank you Usman Farzand. I made backups already, but that doesn't solve the problem.
Any idea of what (or How) could that been caused?

Best Answer

It sounds like the primary key constraints and foreign key references have been dropped from your Odoo database. This could be due to a number of reasons, such as a manual mistake, a bug in the software, or a problem with the database itself.

One way to solve this issue would be to restore a backup of your database that was taken before the primary key constraints and foreign key references were dropped. If you do not have a backup, you will need to manually recreate the primary key constraints and foreign key references.

To recreate the primary key constraints, you will need to run the following SQL command for each table:

ALTER TABLE ADD PRIMARY KEY ();

To recreate the foreign key references, you will need to run the following SQL command for each foreign key:

ALTER TABLE ADD FOREIGN KEY () REFERENCES ();

It is also important to check if there are any data integrity issues and fix them before recreating the foreign keys, as well as to validate that the data still makes sense after recreating the constraints.

It is highly recommended to create a backup of your database before making any changes and test it in a non-production environment first.

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
940
1
Jun 24
3561
3
Feb 24
4252
1
Oct 23
8589
1
Oct 23
97