Odoo 12 Development Essentials
上QQ阅读APP看书,第一时间看更新

Database selection options

When developing with Odoo, it is common to work with several databases, and sometimes even with different Odoo versions. Stopping and starting different server instances on the same port, and switching between different databases, can cause web client sessions to behave improperly. This is because the browser stores session cookies.

Accessing our instance using a browser window running in private mode can help avoid some of these problems.

Another good practice is to enable a database filter on the server instance to ensure that it only allows requests for the database we want to work with, ignoring all others.

Changed in Odoo 11
Since Odoo 11, the --database (or -d) server option accepts a comma-separated list of database names, and setting the --database option automatically also sets the --db-filter option, so that only these databases can be used by that server instance. For versions before Odoo 11, we need to use --db-filter to limit the databases accessible through this server.

The --db-filter option limits the databases that an Odoo server instance can work with. It accepts a regular expression to be used as a filter for valid database names. To match an exact name, the expression should begin with ^ and end with $.

For example, to allow only the testdb database, we would use this command:

$ ~/odoo-dev/odoo/odoo-bin --db-filter=^testdb$

It is a good practice for the --database and --db-filter options to match the same database. In fact, since Odoo 11, this is the default, since setting --database by default sets the corresponding --db-filter.