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

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

class NurseCall(ModelSQL, ModelView):
	"Nurse Call"
	__name__ = ""

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

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

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

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

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.

1 Like

its worked, thank you :face_holding_back_tears:

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