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

Hi,
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:
            return self.specialty.name

    @classmethod
    def __setup__(cls):
        super(HealthInstitutionSpecialties, cls).__setup__()
        t = cls.__table__()
        cls._sql_constraints = [
            (
                "name_sp_uniq",
                Unique(t, t.name, 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\wrappers.py", line 197, in wrapper
    return func(request, pool, *args, **kwargs)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\protocols\dispatcher.py", line 196, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\wizard\wizard.py", line 340, in execute
    result = wizard._execute(state_name)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\wizard\wizard.py", line 380, in _execute
    result = self._execute(transition())
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\ir\module.py", line 505, in transition_upgrade
    pool.init(update=update, lang=lang)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\pool.py", line 167, in init
    restart = not load_modules(
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\modules\__init__.py", line 389, in load_modules
    _load_modules(update)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\modules\__init__.py", line 352, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\modules\__init__.py", line 253, in load_module_graph
    model._update_sql_indexes()
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\model\modelsql.py", line 517, in _update_sql_indexes
    table_h.set_indexes(indexes)
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\backend\postgresql\table.py", line 506, in set_indexes
    cursor.execute(
  File "d:\Milestone\umbrella\venv\lib\site-packages\trytond\backend\postgresql\database.py", 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!!!?

Thanks,

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.