【发布时间】:2019-09-26 13:20:29
【问题描述】:
我正在创建一个 phoenix api 应用程序。这是我的代码。
alias CardsWeb.Repo
alias CardsWeb.Infrastructure.User
Repo.insert! %User{login: "user", firstname: "User", lastname: "User", dateOfBirth: "1999-5-18"}
运行时出现以下错误
** (CompileError) priv/repo/seeds.exs:15: Infrastructure.User.__struct__/1 is undefined, cannot expand struct Infrastructure.User
这是实体定义。
defmodule Infrastructure.User do
use Ecto.Schema
import Ecto.Changeset
schema "users" do
field :dateOfBirth, :date
field :firstName, :string
field :lastName, :string
field :login, :string
timestamps()
end
@doc false
def changeset(user, attrs) do
user
|> cast(attrs, [:login, :firstName, :lastName, :dateOfBirth])
|> validate_required([:login, :firstName, :lastName, :dateOfBirth])
end
end
更新:我注意到名字和姓氏应该是名字和姓氏。我更正了,但我仍然遇到同样的错误。
【问题讨论】:
标签: elixir phoenix-framework seeding