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:
- First visit Odoo portal /
-
System detection:
- Does the demo database already exist?
- If it does not exist → automatically create
- If exists → auto redirect to enter
- 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:
- Call Odoo API to check if demo_db exists
- If it does not exist → call Odoo's internal service to automatically create
- Automatically redirect to /web?db=demo_db after creation
- The administrator initial password is read from the configuration or environment variable.
- A set of modules can be automatically installed
- 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
-
Docker + Configuration File Method
-
Custom Auto-Create Module
→ Control initialization behavior, jumps, data templates
-
Custom Auto-Create Module
-
Reverse proxy redirect
→ Let users access the database seamlessly
-
Reverse proxy redirect
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 |
