title: Odoo How to solve return self.models[model_name]
body: <p>I created 2 custom modules, &quot;projects&quot; and &quot;laboratory&quot;.
  Laboratory module has one2many field of projects.
  Project module has many2one field of laboratory id.</p>
  <p>I made some modification of &quot;laboratory&quot; module and when I tried update it I get this error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 624, in _handle_exception
      return super(JsonRequest, self)._handle_exception(exception)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 310, in _handle_exception
      raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\tools\pycompat.py&quot;, line 14, in reraise
      raise value
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 669, in dispatch
      result = self._call_function(**self.params)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 350, in _call_function
      return checked_call(self.db, *args, **kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\service\model.py&quot;, line 94, in wrapper
      return f(dbname, *args, **kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 339, in checked_call
      result = self.endpoint(*a, **kw)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 915, in __call__
      return self.method(*args, **kw)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 515, in response_wrap
      response = f(*args, **kw)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\web\controllers\main.py&quot;, line 1326, in call_button
      action = self._call_kw(model, method, args, kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\web\controllers\main.py&quot;, line 1314, in _call_kw
      return call_kw(request.env[model], method, args, kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\api.py&quot;, line 387, in call_kw
      result = _call_kw_multi(method, model, args, kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\api.py&quot;, line 374, in _call_kw_multi
      result = method(recs, *args, **kwargs)
    File &quot;&lt;decorator-gen-65&gt;&quot;, line 2, in button_immediate_upgrade
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\base\models\ir_module.py&quot;, line 72, in check_and_log
      return method(self, *args, **kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\base\models\ir_module.py&quot;, line 634, in button_immediate_upgrade
      return self._button_immediate_function(type(self).button_upgrade)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\base\models\ir_module.py&quot;, line 573, in _button_immediate_function
      modules.registry.Registry.new(self._cr.dbname, update_module=True)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\registry.py&quot;, line 86, in new
      odoo.modules.load_modules(registry._db, force_demo, status, update_module)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\loading.py&quot;, line 419, in load_modules
      force, status, report, loaded_modules, update_module, models_to_check)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\loading.py&quot;, line 315, in load_marked_modules
      perform_checks=perform_checks, models_to_check=models_to_check
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\loading.py&quot;, line 202, in load_module_graph
      registry.init_models(cr, model_names, {'module': package.name}, new_install)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\registry.py&quot;, line 348, in init_models
      model._auto_init()
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\models.py&quot;, line 2482, in _auto_init
      new = field.update_db(self, columns)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\fields.py&quot;, line 2417, in update_db
      comodel = model.env[self.comodel_name]
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\api.py&quot;, line 463, in __getitem__
      return self.registry[model_name]._browse(self, (), ())
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\registry.py&quot;, line 177, in __getitem__
      return self.models[model_name]
  KeyError: 'projects'
  </code></pre>
  <p>As I googled this error, it seems that I didn't put dependencies of my module &quot;projects&quot;.</p>
  <p>So, next step was put dependencies:</p>
  <pre><code># any module necessary for this one to work correctly
      'depends': ['base','mail','projects'],
  </code></pre>
  <p>And now I get another error which is saying about dependencies on it self:</p>
  <pre><code>Odoo Server Error
  Traceback (most recent call last):
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 624, in _handle_exception
      return super(JsonRequest, self)._handle_exception(exception)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 310, in _handle_exception
      raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\tools\pycompat.py&quot;, line 14, in reraise
      raise value
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 669, in dispatch
      result = self._call_function(**self.params)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 350, in _call_function
      return checked_call(self.db, *args, **kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\service\model.py&quot;, line 94, in wrapper
      return f(dbname, *args, **kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 339, in checked_call
      result = self.endpoint(*a, **kw)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 915, in __call__
      return self.method(*args, **kw)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\http.py&quot;, line 515, in response_wrap
      response = f(*args, **kw)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\web\controllers\main.py&quot;, line 1326, in call_button
      action = self._call_kw(model, method, args, kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\web\controllers\main.py&quot;, line 1314, in _call_kw
      return call_kw(request.env[model], method, args, kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\api.py&quot;, line 387, in call_kw
      result = _call_kw_multi(method, model, args, kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\api.py&quot;, line 374, in _call_kw_multi
      result = method(recs, *args, **kwargs)
    File &quot;&lt;decorator-gen-66&gt;&quot;, line 2, in button_immediate_upgrade
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\base\models\ir_module.py&quot;, line 72, in check_and_log
      return method(self, *args, **kwargs)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\base\models\ir_module.py&quot;, line 634, in button_immediate_upgrade
      return self._button_immediate_function(type(self).button_upgrade)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\addons\base\models\ir_module.py&quot;, line 573, in _button_immediate_function
      modules.registry.Registry.new(self._cr.dbname, update_module=True)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\registry.py&quot;, line 86, in new
      odoo.modules.load_modules(registry._db, force_demo, status, update_module)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\loading.py&quot;, line 419, in load_modules
      force, status, report, loaded_modules, update_module, models_to_check)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\loading.py&quot;, line 315, in load_marked_modules
      perform_checks=perform_checks, models_to_check=models_to_check
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\loading.py&quot;, line 176, in load_module_graph
      registry.setup_models(cr)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\registry.py&quot;, line 255, in setup_models
      model._setup_fields()
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\models.py&quot;, line 2690, in _setup_fields
      field.setup_full(self)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\fields.py&quot;, line 431, in setup_full
      self._setup_regular_full(model)
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\fields.py&quot;, line 2897, in _setup_regular_full
      comodel = model.env[self.comodel_name]
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\api.py&quot;, line 463, in __getitem__
      return self.registry[model_name]._browse(self, (), ())
    File &quot;C:\Odoo13\Odoo 13.0\server\odoo\modules\registry.py&quot;, line 177, in __getitem__
      return self.models[model_name]
  KeyError: 'laboratory'
  </code></pre>
  <p>And when I change dependency and add self module like this:</p>
  <pre><code># any module necessary for this one to work correctly
      'depends': ['base','mail','projects','laboratory'],
  </code></pre>
  <p>I am getting 500 Internal Server Error.</p>
  <p>Could somebody explain why it happens and how I can handle it?</p>