Hi,
Newbie to Elixir/Phoenix. I come from a Rails background but I’m loving Elixir/Phoenix so far.
When I try to run “mix test”, I’m getting the following error:
** (Postgrex.Error) ERROR (undefined_column): column "inserted_at" of relation "schema_migrations" does not exist
(ecto) lib/ecto/adapters/sql.ex:463: Ecto.Adapters.SQL.struct/6
(ecto) lib/ecto/repo/schema.ex:397: Ecto.Repo.Schema.apply/4
(ecto) lib/ecto/repo/schema.ex:193: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
(ecto) lib/ecto/repo/schema.ex:124: Ecto.Repo.Schema.insert!/4
(ecto) lib/ecto/adapters/sql.ex:508: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
(db_connection) lib/db_connection.ex:1274: DBConnection.transaction_run/4
(db_connection) lib/db_connection.ex:1198: DBConnection.run_begin/3
(db_connection) lib/db_connection.ex:789: DBConnection.transaction/3
My migrations is as follows:
def change do
drop_if_exists table(:users)
create table(:users, primary_key: false) do
add :username, :string, primary_key: true, null: false
add :password, :string, null: false
add :nickname, :string, unique: true
add :verification_code, :string
add :phone_verified, :boolean, default: false, null: false
add :max_distance, :integer
add :distance_unit, :string, default: "km", null: false
timestamps([{:inserted_at,:created_at}, {:updated_at, false}])
end
create unique_index(:users, [:username])
create unique_index(:users, [:nickname])
end
My schema is as follows:
@primary_key {:username, :string, []}
@derive {Phoenix.Param, key: :username}
schema "users" do
field :nickname, :string
field :verification_code, :string
field :phone_verified, :boolean, default: false
field :password, :string
field :max_distance, :integer
field :distance_unit, :string
timestamps([{:inserted_at,:created_at}, {:updated_at, false}])
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:nickname, :verification_code, :phone_verified, :password, :max_distance, :distance_unit])
|> validate_required([:username, :nickname, :phone_verified, :password])
end
When I look in my database, I see that the “schema_migrations” table does indeed have an “inserted_at” column, which is where I’m assuming the error is coming from but I haven’t created that column (as far as I can tell).
Any insight?