Aswani
Aswani

Reputation: 11

How to rectify database restore error in odoo12?

I have got the following error while restoring a database with attachments in odoo12.

I created a python virtual environment and installed odoo12 within the virtual environment and tried to restore a database. But the same error also occurs in the virtual environment also.

hrms_db_1 odoo.sql_db: bad query: INSERT INTO "ir_attachment" ("id", "create_uid", "create_date", "write_uid", "write_date", "active", "company_id", "datas_fname", "mimetype", "name", "public", "res_id", "res_model", "type") VALUES (nextval('ir_attachment_id_seq'), 1, (now() at time zone 'UTC'), 1, (now() at time zone 'UTC'), true, 1, 'web.assets_common.js', 'application/javascript', '/web/content/js', true, 0, 'ir.ui.view', 'binary') RETURNING id 
ERROR: relation "ir_attachment_id_seq" does not exist LINE 1: ...", "res_id", "res_model", "type") VALUES (nextval('ir_attach...

Upvotes: 1

Views: 2289

Answers (3)

Gaston Carrera
Gaston Carrera

Reputation: 11

"AS INTEGER" in every "CREATE SEQUENCE" which is not supported in PostgreSQL 9.6. To work around this, you need to unzip your backup file, open & edit your dump.sql file and delete every occurrence of "AS INTEGER" from every "CREATE SEQUENCE" statement.

This works perfect for me, but how do this can be some difficult when the weight of the file surpasses the 1GB. I recommend use the SublimeText , text editor thats shows you the load bar when open the file (for that you can know what the program dont crash) , and then its only search reading the first lines until find the "CREATE SEQUENCE ir_ModelExample_id_seq

as integer

START WITH 1

..."

then select since "id_seq" until "as integer" (all words included) and stand pressed "ctrl+d", then the sublime text go to multi-select all the other appearances until stop, and then (you gonna be in the muti-select-cursors function) press rigth arrow (putting the cursor at the end of the all "as integer" lines), and erase the line "as integer" stopping when the cursor was in the las position that the previous line "id_seq|" (| its the cursor) , then you gonna be editing all the appearances at the same time. Then Save and actualize in the .zip file, and its Done.

Upvotes: 0

Antonio Ortega
Antonio Ortega

Reputation: 61

From https://github.com/Yenthe666/auto_backup/issues/79#issuecomment-420711666

Issue was because of different postgres versions on Odoo & Database server. Postgres 9.x vs 10

  • Apparently there is a single statement that causes this when creating sequences, which is the "AS INTEGER" in every "CREATE SEQUENCE" which is not supported in PostgreSQL 9.6. To work around this, you need to unzip your backup file, open & edit your dump.sql file and delete every occurrence of "AS INTEGER" from every "CREATE SEQUENCE" statement. Then zip the contents again and try to restore one more time. It will work.

Upvotes: 2

Pablo Escobar
Pablo Escobar

Reputation: 685

Check whether the Python Interpreter you assigned is the right one, means virtual env.enter image description here

Also, check the connectivity with the database and the odoo and custom addons folder permissions too.

Upvotes: 1

Related Questions