Postgrex.Error while running mix test

Hi all.
I am trying to run mix test in my phoenix app.
and then I got error like this.

** (Postgrex.Error) ERROR 42804 (datatype_mismatch): column "counts" cannot be cast automatically to type integer
    (ecto) lib/ecto/adapters/sql.ex:200: Ecto.Adapters.SQL.query!/5
    (ecto) lib/ecto/adapters/postgres.ex:96: anonymous fn/4 in Ecto.Adapters.Postgres.execute_ddl/3
    (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ecto) lib/ecto/adapters/postgres.ex:96: Ecto.Adapters.Postgres.execute_ddl/3
    (ecto) lib/ecto/migration/runner.ex:104: anonymous fn/2 in Ecto.Migration.Runner.flush/0
    (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ecto) lib/ecto/migration/runner.ex:102: Ecto.Migration.Runner.flush/0
    (stdlib) timer.erl:181:

I resolved this error in my database when they came up first in this way

ALTER TABLE the_table ALTER COLUMN col_name TYPE integer USING (col_name::integer);

But It showed up again while execute mix test
I am very new to ex_unit and test environment.

I think it happens when ex_unit makes(?) test database?
How can I solve this problem?

Don’t resolve the error with sql command, resolve it with migration, or update your column type in schema.

You might also want to check this post (Postgrex.Error) ERROR 42804 (datatype_mismatch): column "" cannot be cast automatically to type integer.

1 Like