Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 39 ยท Concepts and Setup

Databases and Developer Mode

See how an Odoo database is organised, how ir_model tables describe models and fields, how to back up and restore, and how developer mode helps.

An Odoo database is more than your customers and invoices. It also stores the description of the system: which models exist, which fields they have, which views and menus are defined, and which modules are installed. This self-describing design is why Odoo can show you its own structure in the Technical menu and why modules can extend each other safely.

In this lesson you will tour that structure, learn how to back up and restore databases, and use developer mode to answer the question every developer asks daily: "where does this come from?"

Data tables and metadata tables

Open a PostgreSQL client such as psql on a demo database and list the tables. You will find two kinds:

  • Business tables, named after models with dots replaced by underscores: res_partner, sale_order, sale_order_line, product_template.
  • Technical tables, whose names start with ir_ ("information repository") or res_: ir_model, ir_model_fields, ir_ui_view, ir_ui_menu, ir_act_window, ir_model_data, ir_module_module, ir_attachment, ir_cron.

A few of these deserve a place in your head:

Table What it records
ir_module_module Every module the server found, and its state (installed, uninstalled, to upgrade)
ir_model One row per model, such as res.partner
ir_model_fields One row per field of every model
ir_model_data External identifiers: a stable name like base.main_company mapped to a record id
ir_ui_view Stored view definitions (XML text)
ir_model_access Access rights per group and model
ir_cron Scheduled jobs

The metadata is filled when a module is installed or updated. The ORM reads your Python class, then creates or alters the table and inserts rows in ir_model and ir_model_fields to match.

flowchart LR
    P["Python class<br/>_name = 'vet.pet'"] -->|"module install / update"| M["ir_model<br/>ir_model_fields"]
    P --> T["table vet_pet<br/>(columns for fields)"]
    X["XML data files"] --> V["ir_ui_view<br/>ir_ui_menu<br/>ir_act_window"]
    X --> ID["ir_model_data<br/>(external ids)"]

Installing a module turns code into tables, metadata rows and view records.

A runnable stand-in: self-describing tables

SQLite is available in the browser, so we can model the idea. The stand-in creates a tiny metadata table, registers a model with its fields, and then builds the real table from the description. It is a model of the principle, not Odoo's real schema.

Python Stand-in: metadata describes the data tables

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

External identifiers

Records created from XML get an external id (also called XML id), written module.name, for example base.user_admin. The pair is stored in ir_model_data, together with the model and the numeric id. Why not use numeric ids? Because ids differ between databases (your demo and production have different numbers), while sale.menu_sale_order is the same everywhere. External ids let a module refer to records from other modules, update its own records when upgraded and clean them up on uninstall. The next chapters use them constantly.

Backup and restore

Odoo has two parts to back up: the PostgreSQL database and the filestore (attachments on disk). The database manager can create a zip backup of both, containing a SQL dump and the files, which can be restored through the same screen. For production you automate dumps with pg_dump and copy the filestore with a tool like rsync (chapter 8). Always test a restore at least once.

Read-only commands for reference:

Terminal
# SQL dump of one database
pg_dump -U odoo -Fc demo > demo.dump

# Restore into a fresh database
createdb -U odoo demo_copy
pg_restore -U odoo -d demo_copy demo.dump

If you restore a copy for testing, deactivate outgoing mail and scheduled actions first, so the copy does not send real emails to real customers. Recent Odoo versions provide a "neutralize" command for that purpose; check your version's documentation.

Developer mode tools

With developer mode on (?debug=1), the debug menu offers:

  • Edit View: Form (and List, Kanban...): open the XML of the current view. Changing it here modifies the database copy of the view only, and a later module upgrade can overwrite your change. Use it for experiments, not for permanent work.
  • View Metadata: shows the record's id, external id, creation date and creator.
  • Fields view: a table of all fields of the model with technical names and types.
  • Technical menu (Settings, Technical): browse models, fields, views, actions, menus, scheduled actions, access rights and record rules.
  • Run tests and an assets debug mode in some versions, to see unminified JavaScript.

Use the debug menu to find the technical name of a field you want to put in a custom report or domain, which is faster than guessing.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What kind of data does the ir_model_fields table hold?

    Odoo records each field's name, type and model so the system can describe itself.
  2. 2. Why does Odoo prefer external ids such as base.user_admin to numeric ids?

    Numeric ids depend on insertion order in each database. External ids give a module a stable name for a record.
  3. 3. What must be backed up besides the PostgreSQL database?

    Attachments and other binary files are on disk in the filestore, so a database dump alone is incomplete.
  4. 4. A colleague edits a view with Edit View in developer mode. What is the risk?

    The edit changes the stored view record, but the module's XML file is the source of truth and is reloaded on update.

Summary

  • A database holds business tables (sale_order) and technical tables prefixed ir_.
  • ir_model and ir_model_fields describe the models; ir_model_data stores external ids.
  • Installing or updating a module turns your Python and XML into tables, metadata and view records.
  • Back up the database and the filestore together, and test restores.
  • Developer mode exposes view editing, metadata, a field list and the Technical menu.

Next: Module Structure and the Manifest