DEV Community

Cover image for Odoo Database Migration
D#ru@ D@v€
D#ru@ D@v€

Posted on

Odoo Database Migration

Odoo Database Migration Using Openupgrade

When Odoo introduces new versions, it includes so many new functionalities and new modules.

We all want to take advantage of newly added functionality and of course our clients also want their projects to be up-to-date. So for that we can’t rewrite code every time odoo introduces a new version. so we migrate our code to a new version.

Now what about data ?

In today’s date data is very important. We can’t afford to lose any kind of data. So for that we need to migrate the database.

This blog will guide you on how to migrate Postgres Database using a free automated script.
You can upgrade any version - for example Odoo 9.0 -> Odoo 10.0, Odoo 10 -> Odoo 11.

If you want to migrate from Odoo 9.0 to Odoo 11.0 then you need to first migrate from Odoo 9.0 to Odoo 10.0.

Then we have to do the same migration process on First migrated Database for Odoo 10.0 to Odoo 11.0.

1. Install openupgradelib

First Install openupgradelib using this command,

pip install openupgradelib

then download files from [https://pypi.org/project/openupgradelib/#files]

then extract this folder
Open terminal and goto that folder location (cd /Downloads/openupgradelib-2.0.0) run this command

sudo python setup.py install

2. Configuration and scripting

2.1 Firstly download the migration script:

[https://gist.github.com/DhruvaDave/67be77caf492aa09cdb84c7c51d5ee39]

2.2 Now we need config file

It will be an odoo configuration file. If you don’t have an odoo configuration file don’t worry.
Use this link to download config file (odoo.conf)

[https://gist.github.com/DhruvaDave/67be77caf492aa09cdb84c7c51d5ee39]

In that file change in addons_path according to your requirements :)
Warning : Code should be migrated for .

3. Migration

Now create new directory “openupgrade” in var/tmp

mkdir /var/tmp/openupgrade

Now move config file and migration file in openupgrade folder

cd /var/tmp/openupgrade
sudo cp /odoo-server.conf /var/tmp/openupgrade (Copy config file to openupgrade folder)
sudo cp /migrate.py /var/tmp/openupgrade (Copy migration script to openupgrade folder)

Yeah finally, now it’s time to run migration command

python migrate.py --config=odoo.conf --database=test_prod --run-migrations=10.0 --branch-dir=/var/tmp/openupgrade  

 --config = config file(in which version you want to migrate)
 --database = database which we would like to migrate(installed database)
 --run-migrations = version in which you would like to migrate

4. Check Migration Logs

You can check the log file to see if there are any issues during migrations.
Open terminal and type this command

tail /var/tmp/openupgrade/migration.log -f

Some Known Possible errors and fixes

1.Peer authentication failed for user ""
This error occurs when postgres username or password is incorrect.

So enter the correct username and password.
If still error is coming or password is forgotten then,
You need to change in pg_hba.conf file
In IPV4 section , you need to replace 1 line with below change.

host all all 0.0.0.0/0 all

After this changes restart postgres service,

sudo service postgresql restart

2.Configparser error

pip install future
sudo apt-get install python-configparser

3.File already Exists

rm -rf /var/tmp/openupgrade

See here, [https://doc.therp.nl/openupgrade/]

Hope it helps :)

Tell me What other ideas can you add to this list that I may have not mentioned?

Happy Coding !!!

Top comments (4)

Collapse
 
gary_no_1 profile image
Ravi Krishnan

does it work with migration to Odoo version 12 / 13 also ?

Collapse
 
nmnaufaldo profile image
Nur Muhammad Naufaldo

It's not working I get this error

Traceback (most recent call last):
File ".\migrate-3.py", line 330, in <module>
migrations[version]['addons'],
KeyError: '13.0'

Collapse
 
drakenmario profile image
Mario Vargas

This is a good way to migrate data, another possibility is use the odoo external api and make query's in one side and insert in the new database.

Collapse
 
rb3606 profile image
Balvant Ramani

Configuration path is wrong :)