Odoo Database Migration
Tags: database, migration, odoo, postgres
Published: 2020-07-03 07:12:10

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 <your_poject_folder>.

**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 "<some_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 !!!


{% medium https://medium.com/@dhruvadave5297/odoo-database-migration-3df0050a231c %}