Database Update Procedure | InvenTree

# Database Update Procedure

12 Feb 2026 Oliver

In our recent 1.2.0 release, we updated our underlying django version to from 4.2 to 5.2.

For users running with a PostgreSQL database, Django 5.2 requires a minimum version of PostgreSQL 14. This means that users running PostgreSQL 13 will need to perform a manual update of their database in order to continue using InvenTree with the latest version.

If you are attempting to update to InvenTree 1.2.0 while still running PostgreSQL 13, you will encounter the following error message:

    django.db.utils.NotSupportedError: PostgreSQL 14 or later is required (found 13.23).

In such a case, you will need to perform a database update procedure to migrate your existing database from PostgreSQL 13 to PostgreSQL 14 (or later). This process involves backing up your existing database, installing the new version of PostgreSQL, and then restoring your data into the new database.

## Migration Guide

Note: This procedure was updated on 2026-02-19

Our documentation provides a detailed database migration guide to assist users with this process. We recommend that users perform a backup of their database before attempting the migration, and follow the instructions carefully to ensure a smooth transition to the new database version.

Following is an example of the steps involved in migrating an InvenTree installation from a PostgreSQL 13 database to a PostgreSQL 17 database, in the context of a docker installation. The same principles apply for non-docker installations, but the particular commands may differ.

PostgreSQL 17 is recommended as the target version, as it is supported by both the 1.1.x and 1.2.x versions of InvenTree.

## Starting Conditions

The starting conditions for this migration are as follows:

- InvenTree is installed via docker / docker compose (as per the docker installation instructions)
- The InvenTree version is pinned to 1.1.12 in the `.env` file
- The database is running PostgreSQL 13 (set via the `docker-compose.yml` file).

We also have a data directory, external to the docker containers, with the following structure:

### Target Conditions

The new installation will be running InvenTree 1.2.0 with PostgreSQL 17

### Data Backup

It is prudent to perform a regular backup of the database, before following the migration procedure. This can be done using the `invoke backup` command, as described in the documentation. This will create a backup of the database and media files in the `data/backup` directory.

## Step 1. Ensure Starting Conditions are Met

- `postgres:13` is set in `docker-compose.yml`
- `INVENTREE_VERSION=1.1.12` is set in `.env`
- Database schema has been updated to the latest version:

    docker compose up inventree-db -d
    docker compose run --rm inventree-server invoke update
    docker compose down

## Step 2. Perform Manual Backup

The first step is to perform a backup of the existing database. This step must be performed with the old setup (postgres 13 / InvenTree 1.1.12), before we perform any updates to the software.

First, let’s confirm that we are running the expected version of InvenTree (1.1.12).

To perform the backup, we run the following commands:

    docker compose up inventree-db -d
    docker compose run --rm inventree-server pg_dump postgresql://pguser@inventree-db:5432/inventree -f /home/inventree/data/backup/db_migrations.sql
    docker compose down

Note: You will be prompted for the password for the `pguser` user. This is the password that you set in the `.env` file (default is `pgpassword`).

Note: Do not change the path to the migrations file, this is the internal docker container path, and should not be changed.

This will create a backup of the database and media files in the `inventree-data/backup` directory (external to the docker containers). The database backup will be saved as `db_migrations.sql`.

Confirm that the backup files have been created before continuing to the next step.

## Step 3. Move Database Directory

The PostgreSQL database files are stored in the `inventree-data/pgdb` directory. We need to remove these files, as they are specific to PostgreSQL 13 and will not be compatible with PostgreSQL 17. Rather than deleting them, we will move them to a backup location, just in case we need to revert back to the old setup.

    mv inventree-data/pgdb inventree-data/pgdb_backup

Confirm that the `pgdb` directory has been moved to the backup location before continuing to the next step. The `pgdb` directory should no longer exist in the `inventree-data` directory.

## Step 4. Update PostgreSQL Version

Next, we need to update the PostgreSQL version in the `docker-compose.yml` file. Change the version from `postgres:13` to `postgres:17`:

Pull down the updated docker images:

    docker compose pull

## Step 4. Restore Data from Backup

Now we can restore the data from the backup we created previously, into the new PostgreSQL 17 database. Run the following commands:

    docker compose up inventree-db -d
    docker compose run --rm inventree-server psql postgresql://pguser@inventree-db:5432/inventree -f /home/inventree/data/backup/db_migrations.sql
    docker compose down

This will restore the database and media files from the backup we created previously.

## Step 5. Verify Database Update

Launch the InvenTree server, and confirm that you can still access your data via the web interface.

    docker compose up -d

Once you have confirmed that the data is accessible, you can stop the server again:

    docker compose down

## Step 6. Update InvenTree Version

Next, we need to update the InvenTree version in the `.env` file. Change the version from `1.1.12` to `1.2.0`:

Then, we need to pull down the updated InvenTree server image:

    docker compose pull

Next, run the InvenTree update procedure:

    docker compose up inventree-db -d
    docker compose run --rm inventree-server invoke update

## Step 7. Verify New Setup

Finally, we can start the new setup and verify that everything is working as expected.

    docker compose up -d

Then, you should be able to access your InvenTree instance again, and confirm that you are running the new version (1.2.0):

We can also see that the correct versions of both PostgreSQL and InvenTree are running in the docker containers:

## Step 8. Celebrate!

Congratulations! You have successfully migrated your InvenTree installation to the latest version, with an updated PostgreSQL database. You can now enjoy the new features and improvements that come with InvenTree 1.2.0, while also benefiting from the enhanced performance and security of PostgreSQL 17.

Please consider sponsoring the project, to help us continue to maintain and improve InvenTree for all users. Your support is greatly appreciated!