[Solved]-Postgresql operator class "varchar_pattern_ops" does not accept data type integer

9๐Ÿ‘

โœ…

Iโ€™m only able to reproduce your error message like so:

denis=# create index test_idx on test (val varchar_pattern_ops);
CREATE INDEX
denis=# alter table test alter val type int using (val::int);
ERROR:  operator class "varchar_pattern_ops" does not accept data type integer

If youโ€™ve a funky index like that, try dropping and recreating it like so:

denis=# drop index test_idx;
DROP INDEX
denis=# create index test_idx on test (val);
CREATE INDEX
denis=# alter table test alter val type int using (val::int);
ALTER TABLE

Related docs:

http://www.postgresql.org/docs/current/static/indexes-opclass.html

14๐Ÿ‘

Dealing with this problem you have to use 2 steps of migrations.

First: Add db_index=False on your first migration then generate and run the migration.

Second: Update db_index=True to your related column in the model (according to the first step) then generate the migration and run again.

This is based on my experience on some projects, and it works.

Hope it helps.

Leave a comment