psycopg2.errors.DatatypeMismatch: operator class "varchar_pattern_ops" does not accept data type integer

The following is my model.

class HealthInstitutionSpecialties(ModelSQL, ModelView):
    "Health Institution Specialties"
    __name__ = "gnuhealth.institution.specialties"

    name = fields.Many2One("gnuhealth.institution", "Institution", required=True)
    specialty = fields.Many2One("gnuhealth.specialty", "Specialty", required=True)

    def get_rec_name(self, name):
        if self.specialty:

    def __setup__(cls):
        super(HealthInstitutionSpecialties, cls).__setup__()
        t = cls.__table__()
        cls._sql_constraints = [
                Unique(t,, t.specialty),
                "The Specialty already exists for this institution",

and when I want to activate it I get the following error:

Traceback (most recent call last):
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\protocols\", line 197, in wrapper
    return func(request, pool, *args, **kwargs)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\protocols\", line 196, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\wizard\", line 340, in execute
    result = wizard._execute(state_name)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\wizard\", line 380, in _execute
    result = self._execute(transition())
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\ir\", line 505, in transition_upgrade
    pool.init(update=update, lang=lang)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\", line 167, in init
    restart = not load_modules(
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\modules\", line 389, in load_modules
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\modules\", line 352, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\modules\", line 253, in load_module_graph
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\model\", line 517, in _update_sql_indexes
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\backend\postgresql\", line 506, in set_indexes
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\backend\postgresql\", line 69, in execute
    cursor.execute(self, sql, args)
psycopg2.errors.DatatypeMismatch: operator class "varchar_pattern_ops" does not accept data type integer

The following query gets executed in the database:
CREATE INDEX IF NOT EXISTS "idx_gnuhealth_institution_specialties_d884bc69b0c18974fe" ON "gnuhealth_institution_specialties" USING BTREE ("name" varchar_pattern_ops)

What to do to get rid of the error!!!?


It is a GNU Health bug, it should not define a Many2One as Model._rec_name: see Document that _rec_name must point to a Char field (!1479) · Merge requests · Tryton / Tryton · GitLab

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