Odoo 11:无法更新模块,因为新模板已添加到模块

Odoo 11: Cant update module because new template was added to the module

我是 Odoo 的新手,我想尝试一下我已经为网页创建了一些视图(模板)的测试模块。起初,当只有一个模板时,一切正常,但是当我尝试添加另一个模板时,更新突然不再起作用了。您会在下面找到第一个和第二个模板的代码以及错误消息以及我的清单文件

第一个模板

<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <template id="template_test_hello_world" name="Test Hello World">&lt;!DOCTYPE html&gt;
        <html>

            <body>
                <div id="test_hello_world_page_text">
                    <p>Url text: <t t-esc="val"/></p>
                </div>
                <div>
                    <t t-foreach="models" t-as="model">
                        <p><t t-esc="model.id"/><t t-esc="model.preview_name"/></p>
                    </t>
                </div>

            </body>

        </html>
    </template>

</odoo>

第二个模板

<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <template id="template_random" name="Test Random">&lt;!DOCTYPE html&gt;
        <html>

            <body>
                <div id="test_random_div">
                    <p>BlaBlaBla</p>
                </div>

            </body>

        </html>
    </template>

</odoo>

清单

{
    'name': "Tests",
    'summary': """
        Testing stuff
    """,
    'description': """
        Yes. 
    """,
    'author': "",
    'website': "",
    'category': 'Uncategorized',
    'version': '0.1',
    'depends': [],
    'data': [
        'views/test_hello_world_template.xml',
        'data/test_models.xml',
        'security/ir.model.access.csv',
        'views/random_template.xml',
    ],
    "installable": True,
}

错误信息

2020-02-07 11:21:47,945 27164 ERROR smthg odoo.sql_db: bad query: b'INSERT INTO "ir_ui_view" ("id", "key", "priority", "active", "type", "name", "mode", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval(\'ir_ui_view_id_seq\'), \'my_module.template_test_hello_world\', 16, true, \'qweb\', \'Test Hello World\', \'primary\', 1, 1, (now() at time zone \'UTC\'), (now() at time zone \'UTC\')) RETURNING id'
ERROR: null value in column "projection" violates not-null constraint
DETAIL:  Failing row contains (2531, 2020-02-07 11:21:47.854173, 1, 2020-02-07 11:21:47.854173, t, null, null, null, Test Hello World, null, 16, primary, null, qweb, 1, null, null, null, null, null, null, my_module.template_test_hello_world, null, null, null, null, null).

2020-02-07 11:21:47,946 27164 WARNING smthg odoo.modules.loading: Transient module states were reset
2020-02-07 11:21:48,044 27164 ERROR smthg odoo.modules.registry: Failed to load registry
Traceback (most recent call last):
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 745, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 723, in _tag_template
    return self._tag_record(record, data_node)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 655, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_model.py", line 1504, in _update
    record = record.create(values)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_ui_view.py", line 408, in create
    return super(View, self).create(self._compute_defaults(values))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3409, in create
    record = self.browse(self._create(old_vals))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3502, in _create
    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 155, in wrapper
    return f(self, *args, **kwargs)
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
psycopg2.IntegrityError: null value in column "projection" violates not-null constraint
DETAIL:  Failing row contains (2531, 2020-02-07 11:21:47.854173, 1, 2020-02-07 11:21:47.854173, t, null, null, null, Test Hello World, null, 16, primary, null, qweb, 1, null, null, null, null, null, null, my_module.template_test_hello_world, null, null, null, null, null).


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/etc/odoo/odoo-server/odoo/odoo/modules/registry.py", line 85, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 376, in load_modules
    force, status, report, loaded_modules, update_module, models_to_check)
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 274, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 181, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 95, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 792, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 853, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 752, in parse
    exc_info[2]
  File "/etc/odoo/odoo-server/odoo/odoo/tools/pycompat.py", line 86, in reraise
    raise value.with_traceback(tb)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 745, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 723, in _tag_template
    return self._tag_record(record, data_node)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 655, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_model.py", line 1504, in _update
    record = record.create(values)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_ui_view.py", line 408, in create
    return super(View, self).create(self._compute_defaults(values))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3409, in create
    record = self.browse(self._create(old_vals))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3502, in _create
    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 155, in wrapper
    return f(self, *args, **kwargs)
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
odoo.tools.convert.ParseError: "null value in column "projection" violates not-null constraint
DETAIL:  Failing row contains (2531, 2020-02-07 11:21:47.854173, 1, 2020-02-07 11:21:47.854173, t, null, null, null, Test Hello World, null, 16, primary, null, qweb, 1, null, null, null, null, null, null, my_module.template_test_hello_world, null, null, null, null, null).
" while parsing None:4, near
<t name="Test Hello World" t-name="my_module.template_test_hello_world">&lt;!DOCTYPE html&gt;
            <html>

                <body>
                    <div id="test_hello_world_page_text">
                        <p>Url text: <t t-esc="val"/></p>
                    </div>
                    <div>
                        <t t-foreach="models" t-as="model">
                            <p><t t-esc="model.id"/><t t-esc="model.preview_name"/></p>
                        </t>
                    </div>

                </body>

            </html>
        </t>
2020-02-07 11:21:48,048 27164 CRITICAL smthg odoo.service.server: Failed to initialize database `smthg`.
Traceback (most recent call last):
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 745, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 723, in _tag_template
    return self._tag_record(record, data_node)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 655, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_model.py", line 1504, in _update
    record = record.create(values)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_ui_view.py", line 408, in create
    return super(View, self).create(self._compute_defaults(values))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3409, in create
    record = self.browse(self._create(old_vals))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3502, in _create
    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 155, in wrapper
    return f(self, *args, **kwargs)
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
psycopg2.IntegrityError: null value in column "projection" violates not-null constraint
DETAIL:  Failing row contains (2531, 2020-02-07 11:21:47.854173, 1, 2020-02-07 11:21:47.854173, t, null, null, null, Test Hello World, null, 16, primary, null, qweb, 1, null, null, null, null, null, null, my_module.template_test_hello_world, null, null, null, null, null).


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/etc/odoo/odoo-server/odoo/odoo/service/server.py", line 1006, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "/etc/odoo/odoo-server/odoo/odoo/modules/registry.py", line 85, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 376, in load_modules
    force, status, report, loaded_modules, update_module, models_to_check)
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 274, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 181, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/etc/odoo/odoo-server/odoo/odoo/modules/loading.py", line 95, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 792, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 853, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 752, in parse
    exc_info[2]
  File "/etc/odoo/odoo-server/odoo/odoo/tools/pycompat.py", line 86, in reraise
    raise value.with_traceback(tb)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 745, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 723, in _tag_template
    return self._tag_record(record, data_node)
  File "/etc/odoo/odoo-server/odoo/odoo/tools/convert.py", line 655, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_model.py", line 1504, in _update
    record = record.create(values)
  File "/etc/odoo/odoo-server/odoo/odoo/addons/base/ir/ir_ui_view.py", line 408, in create
    return super(View, self).create(self._compute_defaults(values))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3409, in create
    record = self.browse(self._create(old_vals))
  File "/etc/odoo/odoo-server/odoo/odoo/models.py", line 3502, in _create
    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 155, in wrapper
    return f(self, *args, **kwargs)
  File "/etc/odoo/odoo-server/odoo/odoo/sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
odoo.tools.convert.ParseError: "null value in column "projection" violates not-null constraint
DETAIL:  Failing row contains (2531, 2020-02-07 11:21:47.854173, 1, 2020-02-07 11:21:47.854173, t, null, null, null, Test Hello World, null, 16, primary, null, qweb, 1, null, null, null, null, null, null, my_module.template_test_hello_world, null, null, null, null, null).
" while parsing None:4, near
<t name="Test Hello World" t-name="my_module.template_test_hello_world">&lt;!DOCTYPE html&gt;
            <html>

                <body>
                    <div id="test_hello_world_page_text">
                        <p>Url text: <t t-esc="val"/></p>
                    </div>
                    <div>
                        <t t-foreach="models" t-as="model">
                            <p><t t-esc="model.id"/><t t-esc="model.preview_name"/></p>
                        </t>
                    </div>

                </body>

            </html>
        </t>

我最感兴趣的可能是第一行:

bad query: b'INSERT INTO "ir_ui_view" ("id", "key", "priority", "active", "type", "name", "mode", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval(\'ir_ui_view_id_seq\'), \'my_module.template_test_hello_world\', 16, true, \'qweb\', \'Test Hello World\', \'primary\', 1, 1, (now() at time zone \'UTC\'), (now() at time zone \'UTC\')) RETURNING id'
ERROR: null value in column "projection" violates not-null constraint
DETAIL:  Failing row contains (2531, 2020-02-07 11:21:47.854173, 1, 2020-02-07 11:21:47.854173, t, null, null, null, Test Hello World, null, 16, primary, null, qweb, 1, null, null, null, null, null, null, my_module.template_test_hello_world, null, null, null, null, null).

但我对 SQL 或 Odoo 了解不多,虽然我花了将近一整天的时间,但我在网上找到的很少,而且,正如你在底部看到的那样第一个模板似乎有问题的错误可能对您有用,让您知道在某些时候显示的是第二个模板。

我想最后我的问题是,有谁知道发生了什么以及我该如何解决这个问题?

对于遇到相同问题的任何人,问题似乎是由损坏的视图引起的。系统的完整更新会强制 Odoo 重新创建每个视图,以便正常工作。这意味着通过在更新命令中将 all 指定为包名称来更新所有包:

odoo-bin -d db -c config -u all