# KeyError: 'gnuhealth.model' when i use Many2One field

**URL:** https://discuss.tryton.org/t/keyerror-gnuhealth-model-when-i-use-many2one-field/6065
**Category:** Developer
**Created:** [April 8, 2023, 7:40am UTC](https://discuss.tryton.org/t/keyerror-gnuhealth-model-when-i-use-many2one-field/6065 "2023-04-08T07:40:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![danhedaiat](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/danhedaiat/32/2262_2.png) [@danhedaiat](https://discuss.tryton.org/u/danhedaiat)
#### Post date: [April 8, 2023, 7:40am UTC](https://discuss.tryton.org/t/keyerror-gnuhealth-model-when-i-use-many2one-field/6065/1 "2023-04-08T07:40:12Z")

</div>

in my module i want to use some relation between the models and my own model, so i do this:

```auto
class NurseCall(ModelSQL, ModelView):
	"Nurse Call"
	__name__ = "arnika.nurse.call"

	name = fields.Many2One('gnuhealth.patient', 'Patient')
	date = fields.DateTime('Date')
	bed = fields.Many2One("gnuhealth.hospital.bed", 'nurse_call')
	health_professional = fields.Many2One('gnuhealth.healthprofessional','Health Professional', readonly=True)
	
	@classmethod
	def __setup__ (cls):
	   super(). __setup__ ()
	   t = cls. __table__ ()
	   cls._sql_constraints = [
	       ('name_uniq', Unique(t, t.name), 'The Name must be unique !'),]

```

and when i run trytond-admin -d test -u module its raise this error :

```auto
Traceback (most recent call last):
  File "gnuhealth/tryton/server/trytond-6.0.27/bin/trytond-admin", line 23, in <module>
    admin.run(options)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-6.0.27/trytond/admin.py", line 53, in run
    pool.init(update=options.update, lang=list(lang),
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-6.0.27/trytond/pool.py", line 164, in init
    restart = not load_modules(
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-6.0.27/trytond/modules/ __init__.py", line 438, in load_modules
    _load_modules(update)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-6.0.27/trytond/modules/ __init__.py", line 406, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-6.0.27/trytond/modules/ __init__.py", line 238, in load_module_graph
    cls. __register__ (module)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-6.0.27/trytond/model/modelsql.py", line 264, in __register__
    ref_model = pool.get(field.model_name)
  File "/home/gnuhealth/gnuhealth/tryton/server/trytond-6.0.27/trytond/pool.py", line 187, in get
    return self._pool[self.database_name][type][name]
KeyError: 'gnuhealth.hospital.bed'

```

and if I comment the `#bed = fields.Many2One("gnuhealth.hospital.bed", 'nurse_call')` line, i still get this error but for one of other field and all of module are activated

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [April 8, 2023, 9:38am UTC](https://discuss.tryton.org/t/keyerror-gnuhealth-model-when-i-use-many2one-field/6065/2 "2023-04-08T09:38:31Z")

</div>

This sounds like you have dependency declaration issue. If your module is using model declared in other modules, you must declare the other module as a dependency. So it is loaded before yours and the models will be in the pool when needed.

---

<div class="post-metadata">

### Author: ![danhedaiat](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/danhedaiat/32/2262_2.png) [@danhedaiat](https://discuss.tryton.org/u/danhedaiat)
#### Post date: [April 8, 2023, 10:13am UTC](https://discuss.tryton.org/t/keyerror-gnuhealth-model-when-i-use-many2one-field/6065/4 "2023-04-08T10:13:19Z")

</div>

its worked, thank you 🥹

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [May 8, 2023, 10:14am UTC](https://discuss.tryton.org/t/keyerror-gnuhealth-model-when-i-use-many2one-field/6065/5 "2023-05-08T10:14:17Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
