How to migrate binary field to filestorage


By default Tryton stores the data in binary fields in the database, but thanks to the Binary.file_id attribute it is possible to store this data in the FileStore instead. The main goal of doing this is to reduce the size of the database.

Here is a technique you can use to move existing binary data out of the database and into the FileStore.


You must first setup the Binary.file_id. Some modules provide a configuration option that can be used to switch on this behavior for their binary fields like the Account Invoice Module.

When changing the configuration, the server must be restarted.


To move any existing data you can use a trytond-console script which will clean out the database column and add the file to the FileStore.

Here is an example for the invoice report cache that can be pasted into the trytond-console:

models = [pool.get('account.invoice')]
except KeyError:

limit = 1000

for Model in models:
    while True:
        records =[
                ('invoice_report_cache', '!=', None),
                ], order=[('id', 'ASC')], limit=limit)
        if not records:
        for record in records:
            report = record.invoice_report_cache  # backup the data
            record.invoice_report_cache = None   # clean the database column
            record.invoice_report_cache = report  # restore the data

A post was split to a new topic: Migrate only half of binary fields