This question has been flagged

Hi, I got this error in odoo 12 after importing a database from a computer to another:

psycopg2.ProgrammingError: relation «ir_attachment_id_seq» does not exist
LINE 1: ...res_model", "type", "website_id") VALUES (nextval('ir_attach...
^
Error to render compiling AST
ProgrammingError: no existe la relación «ir_attachment_id_seq»
LINE 1: ...res_model", "type", "website_id") VALUES (nextval('ir_attach...
^
Template: website.layout
Path: /templates/t/t/t[5]/t[6]
Node:

The error was because the original database was Postgres 10 but my local database is Postgres 9.6, the dump.sql file in the .zip file contains "to integer" in the script and Postgres 9.X doesn't support this operation.

To fix this error you need decompress the .zip file and edit the dump.sql deleting all the "to integer", after deleting all ocurrence compress all the files again and restore the backup.

If your dump.sql file is larger than 500 MB I recomend using a terminal text like nano or vim in linux to replace all the "as integer" ocurrencies to avoid overflowing your RAM memory



Avatar
Discard
Best Answer

I had a similar issue on a custom table that I had changed the name of.

The fix was to recreate the sequence in the database (through pgadmin or other database management tool)

My table was called 'sale_partexchange' so you can just replace the table name with your one and run the following SQL statement.

DROP SEQUENCE IF EXISTS sale_partexchange_id_seq;
CREATE SEQUENCE sale_partexchange_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;


Avatar
Discard
Best Answer

im having a pretty weird problem as well, when i try to go into "Technical -> sequencing" in order to change the sequence number of my invoices, i get inmediatly a server error, where it says

Traceback (most recent call last):
  File "/odoo/odoo-server/odoo/api.py", line 1039, in get
    value = self._data[key][field][record._ids[0]]
KeyError: 254

so i cannot change the invoice sequences, at the same time, checking the history of invoices, the sequence never changed the year from 2021, it stuck, right now begginning 2023, we have inv/2021/0001

Avatar
Discard
Best Answer

This will do the job. Run in PGADMIN or commandline
remove -- to execute

DO $$
DECLARE
_record RECORD;
_max BIGINT;
_exec VARCHAR;

BEGIN

FOR _record IN
(
SELECT table_schema,
*
FROM information_schema.COLUMNS
WHERE column_name = 'id' and table_name != 'xxx')
LOOP
execute format('select max(id) from %s', _record.table_name) into _max;

IF _max is NULL THEN
_max = 1;
ELSE
_max = _max + 10;
END IF;

_exec = 'CREATE SEQUENCE IF NOT EXISTS ' || _record.table_name || '_id_seq START ' || _max;
RAISE INFO '%', _exec;

execute _exec;



END LOOP;
END;
$$ ;


Avatar
Discard
Best Answer
  • 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.

(Refered from stackoverflow)


Avatar
Discard