Ecto Migration throwing error - (Postgrex.Error) ERROR 42601 (syntax_error)

Hi everyone!, I am currently running an ecto migration but it keeps throwing an error that I cannot locate. Below is the migration:

def up do
    create table(:user_details) do
      add :user_id, :bigint, null: false
      add :email, :string, null: false
      add :full_name, :string, null: false
      add :phone_number, :integer, size: 10, null: false
      add :school_id, :integer, null: false
      add :year_completed, :integer, size: 4, null: false
      add :active_status, :boolean, default: true
      add :del_status, :boolean, default: false
      add :created_at, :utc_datetime, default: fragment("now()")
      add :updated_at, :utc_datetime
    create unique_index(:user_details, [:email, :user_id, :phone_number])

And when I run mix ecto.migrate, I get the following error.
** (Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or near “(”

query: CREATE TABLE "user_details" ("id" bigserial, "user_id" bigint NOT NULL, "email" varchar(255) NOT NULL, "full_name" varchar(255) NOT NULL, "phone_number" integer(10) NOT NULL, "school_id" integer NOT NULL, "year_completed" integer(4) NOT NULL, "active_status" boolean DEFAULT true, "del_status" boolean DEFAULT false, "created_at" timestamp(0) DEFAULT now(), "updated_at" timestamp(0), PRIMARY KEY ("id"))
(ecto_sql) lib/ecto/adapters/sql.ex:629: Ecto.Adapters.SQL.raise_sql_call_error/1
(elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
(ecto_sql) lib/ecto/adapters/sql.ex:716: Ecto.Adapters.SQL.execute_ddl/4
(ecto_sql) lib/ecto/migration/runner.ex:338: Ecto.Migration.Runner.log_and_execute_ddl/3
(ecto_sql) lib/ecto/migration/runner.ex:117: anonymous fn/6 in Ecto.Migration.Runner.flush/0
(elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto_sql) lib/ecto/migration/runner.ex:116: Ecto.Migration.Runner.flush/0
(stdlib) timer.erl:166:

I need help urgently. Thank you all

Guys, my bad. I have been able to figure out the solution.
The problem was, I was trying to use size on an integer type column with Postgres currently does not support. So after changing the type to string, it went through.


1 Like