Odoo 19 首次登录自动创建数据库方案:自动生成 Demo 库的最佳实践

Odoo 19 Automatic Database Creation Scheme on First Login

——A complete solution that automatically generates a Demo database upon access after installation

​In the default behavior of Odoo 19, the first visit to the system stays on the database selection page (/web/database/selector). The administrator needs to manually click "Create Database" to create a new database, or select an existing one to log in.

However, in some scenarios, this default behavior does not meet the requirements, for example:

  • The SaaS model expects users to obtain an automatically created trial database upon their first visit;
  • The internal environment expects Odoo to be ready for direct system access upon installation, without the need for manual database creation;
  • The Demo/demo environment needs to consistently generate a demo library and automatically navigate into it;
  • In automated deployment scenarios, a zero-touch experience is desired.

This article will comprehensively introduce how to implement the ability to "automatically create a database on first visit" in Odoo 19 from four levels: principles, implementation methods, configuration approaches, and enhancement solutions.

1. Default Database Creation Behavior of Odoo 19

Odoo 19 enables the dbfilter mechanism by default after installation:

  • When no database is specified, the database management page will be entered.
  • Users need to manually enter the database name, admin email, password, and other content to complete initialization.

This method is not beginner-friendly and is not suitable for automated deployment.

2. Requirements Analysis: Logic for Automatically Creating Demo Database

The target behavior is as follows:

  1. First visit Odoo portal /
  2. System detection:
    • Does the demo database already exist?
    • If it does not exist → automatically create
    • If exists → auto redirect to enter
  3. Users can directly enter the backend interface without clicking any button.

The automatically created Demo database can contain:

  • Specify a name (e.g., demo_db)
  • Automatically install selected modules (sales, crm, inventory, etc.)
  • Automatically set admin password
  • Inject initial data based on requirements

III. Implementation Plan (Applicable to Odoo 19)

To automatically create a database on the first visit, we can adopt the following "three-tier approach", and you can choose any one or a combination of multiple approaches.

Option 1: Use the --init parameter + specify the default database (simplest)

Suitable for Docker or command-line deployment.

1. Startup parameter syntax

Add in odoo.conf or startup command:

db_name = demo_db

On first startup, if the database does not exist, Odoo will automatically attempt to create a database with the same name.

Paired with automatic installation module:

init = base,website,sale,crm

2. Docker Compose Example

command: >
  odoo --db_host=db --db_user=odoo --db_password=odoo
       --db_name=demo_db
       --init=base,website,sale,crm

3. Features

  • Simple and stable
  • No development needed
  • But does not support advanced logic (e.g., first-visit detection, jump control, etc.)

Option 2: Force path redirection through reverse proxy (zero-touch experience)

When users access /, they are directly redirected to the URL for automatically creating a database.

Nginx Example:

location / {
    return 302 /web?db=demo_db;
}

If automatic database creation (Option 1) is enabled in the Odoo configuration, this method can achieve a true sense of:

Install → Launch → Access via browser → Automatically enter the backend

Option 3 (Recommended): Develop an automatic initialization module (Auto DB Creator)

This is the most flexible, scalable, and production-ready solution for SaaS/self-hosted needs.

Core Idea

Write a custom module that executes the following logic when a user first visits an Odoo route:

  1. Call Odoo API to check if demo_db exists
  2. If it does not exist → call Odoo's internal service to automatically create
  3. Automatically redirect to /web?db=demo_db after creation
  4. The administrator initial password is read from the configuration or environment variable.
  5. A set of modules can be automatically installed
  6. Can automatically import demo data

Code Design Structure

auto_db_creator/
  ├── __manifest__.py
  ├── controllers/
  │     └── main.py
  └── data/
        └── auto_init.xml

controller (core judgment logic)

from odoo import http
from odoo.http import request

class AutoDBCreator(http.Controller):

    @http.route('/', type='http', auth='none')
    def auto_create_db(self, **kwargs):
        db_list = http.db_list()
        target_db = 'demo_db'

        if target_db not in db_list:
            # 自动创建数据库
            request.env['ir.http'].sudo()._create_database(
                target_db,
                admin_password='admin',
                demo=True,
                lang='zh_CN'
            )

        # 自动跳转进入系统
        return http.redirect_with_hash('/web?db=%s' % target_db)

Features

  • Module can be installed automatically
  • Control complex logic (triggered only on first visit)
  • Can be used to batch create sample databases on SaaS platforms
  • Strong scalability, supports adding functions such as auditing, initializing data, and secondary redirection.

4. Advanced: Automatically Generate Multiple Databases (for SaaS)

​If you need to automatically create databases based on subdomains or URLs, you can combine Odoo's built-in dbfilter:

		​dbfilter = ^%h$

​Example:

​ Access:

		​abc.myodoo.com

​System automatically creates and loads:

		​abc

​Combined with the automatic creation module described in this article, dynamic database creation can be achieved.

5. Deployment Suggestions

​To reduce maintenance costs, the recommended approach is as follows:

    • Docker + Configuration File Method
      → Automatically specify db_name + install modules
    • Custom Auto-Create Module
      → Control initialization behavior, jumps, data templates
    • Reverse proxy redirect
      → Let users access the database seamlessly

The combination of the three delivers the best experience.

6. Typical Usage Scenarios

Scene Recommended Plan
Official Demo Option 1 + Option 2
Internal ERP automatic deployment Option 1
SaaS automatically creates multi-tenancy Plan Three (Module)
Zero-interaction installation experience Option 1 + Reverse Proxy Redirect

关于我们

​我们致力于帮助中小企业实现数字化转型,我们的团队由一群充满激情和创新思维的专业人士组成,他们具备丰富的行业经验和技术专长。

扫一扫获取顾问以及手册

归档
登录 留下评论
Odoo19 Docker 部署后如何彻底切断官方数据回传?完整配置教程(含 Docker Compose 示例
Odoo 从很早的版本开始,就默认开启了 Telemetry(远程数据回传/Usage Statistics)。这些数据会周期性上传到 Odoo 官方服务器,包括但不限于:服务器信息、模块使用情况、用户数量、安装情况、系统健康度等。对于部分企业来说,这本身并不是坏事,可以帮助 Odoo 改进产品。