(Postgrex.Error) ERROR 42804 (datatype_mismatch): column "" cannot be cast automatically to type integer

Yeah. That’s a Postgresql restriction. You’ll have to execute SQL to convert it.

alter table users alter column from_id type integer using (from_id::integer);

if you use psql and attempt to do the SQL directly it actually provides a hint on this:

HINT: You might need to specify “USING from_id::integer”.

so:

defmodule TweetBot.Repo.Migrations.AlterUsers do
  use Ecto.Migration

   def up do
      execute """
        alter table users alter column from_id type integer using (from_id::integer)
       """
   end

   def down do
      execute """
        alter table users alter column from_id type character varying(255);
       """
   end
end
15 Likes