Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Error in odoo 12 after restoring database, ProgrammingError: relation "ir_attachment_id_seq" does not exist

Subscribe

Get notified when there's activity on this post

This question has been flagged
databasebackuprestorerestoredbodoo12
6 Replies
10127 Views
Avatar
José Luis Benitez

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:


------ SOLUTION --------


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



0
Avatar
Discard
Avatar
Pranav P S
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)


1
Avatar
Discard
Avatar
Alexander Hilsum
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;
$$ ;


1
Avatar
Discard
Avatar
Forcix BV
Best Answer

@Alexander Hilsum: Thanks a lot for your fix script. It helped me fix my DB with 50 missing indices in no time. I did add two lines to configure the sequence as default nextval on the column:


DO $$

DECLARE

_record RECORD;

_max BIGINT;

_exec VARCHAR;

_exec2 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;

_exec2 = 'alter table ' || _record.table_name || ' alter column id set default nextval(''' || _record.table_name || '_id_seq''::regclass)';

RAISE INFO '%', _exec2;

execute _exec2;


END LOOP;

END;

$$ ;

0
Avatar
Discard
Avatar
ASOP
Best Answer

This Solve:

CREATE SEQUENCE ir_attachment_id_seq START 1;

then 

SELECT setval('ir_attachment_id_seq', (SELECT MAX(id) FROM ir_attachment));

0
Avatar
Discard
Avatar
Oliver Breeden
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;


0
Avatar
Discard
Avatar
nando
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

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Icons Doesn't Show After Restoring Database Solved
database backup restore restoredb databasebackup
Avatar
Avatar
1
Mar 24
9373
how to restore database for different versions of Odoo? Solved
database backup restore restoredb odoo
Avatar
Avatar
1
Aug 15
7944
Restore completes but database not visible Solved
backup restore restoredb
Avatar
Avatar
Avatar
3
Jan 22
6171
Odoo 12 One app free Cloud Hosting Database Restore Problem
database backup restore
Avatar
Avatar
Avatar
2
Sep 19
4546
Error message in restoring database via both zip file and dump file for Odoo 8 Solved
database backup restore
Avatar
Avatar
3
Jun 16
16381
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now