Hey guys, I’m working with an Enum field on my schema, but I’m getting the following error:
(ArgumentError) invalid or unknown type Ecto.Enum for field :status
My migration and schema:
defmodule Livekanb.Repo.Migrations.CreateTasks do
use Ecto.Migration
def change do
create table(:tasks, primary_key: false) do
add :id, :binary_id, primary_key: true
add :title, :string
add :description, :string
add :status, :string
add :relator_user_id, references(:users, on_delete: :nothing, type: :binary_id)
add :executor_user_id, references(:users, on_delete: :nothing, type: :binary_id)
timestamps()
end
create index(:tasks, [:relator_user_id])
create index(:tasks, [:executor_user_id])
end
end
defmodule Livekb.Tasks.Task do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "tasks" do
field :description, :string
field :title, :string
field :status, Ecto.Enum, values: [:todo, :doing, :done, :excluded]
field :relator_user_id, :binary_id
field :executor_user_id, :binary_id
timestamps()
end
@doc false
def changeset(task, attrs) do
task
|> cast(attrs, [:title, :description, :status])
|> validate_required([:title, :description, :status])
end
end
What am I doing wrong?