我正在尝试为我的项目设定种子,但每当我尝试运行seeds.exs时,我都会在下面收到错误。我的一些属性使用ARC依赖项进行文件上传,这就是导致我的错误的原因。我不明白我是如何匹配Arc.Ecto.Type.dump的任何函数子句的。
Repo.insert! Show.changeset(%Show{
title: "NP News",
position: 1,
showimageurl: %Plug.Upload{filename: "file.jpg", path: "http://example.com/file.jpg"},
lcrshowimageurl: %Plug.Upload{filename: "file.jpg", path: "http://example.com/file.jpg"},
shuffleepisodes: true
})
以下是我遇到的错误:
** (FunctionClauseError) no function clause matching in Arc.Ecto.Type.dump/2
(arc_ecto) lib/arc_ecto/type.ex:39: Arc.Ecto.Type.dump(Project.LcrShowImageUploader, %Plug.Upload{content_type: nil, filename: "file.jpg", path: nil})
(ecto) lib/ecto/type.ex:629: Ecto.Type.do_adapter_dump/3
(ecto) lib/ecto/repo/schema.ex:625: Ecto.Repo.Schema.dump_field!/6
(ecto) lib/ecto/repo/schema.ex:638: anonymous fn/6 in Ecto.Repo.Schema.dump_fields!/5
(stdlib) lists.erl:1263: :lists.foldl/3
(ecto) lib/ecto/repo/schema.ex:636: Ecto.Repo.Schema.dump_fields!/5
(ecto) lib/ecto/repo/schema.ex:585: Ecto.Repo.Schema.dump_changes!/6
(ecto) lib/ecto/repo/schema.ex:190: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
(ecto) lib/ecto/repo/schema.ex:614: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/6
(ecto) lib/ecto/adapters/sql.ex:508: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
(db_connection) lib/db_connection.ex:1063: DBConnection.transaction_run/4
(db_connection) lib/db_connection.ex:987: DBConnection.run_begin/3
(db_connection) lib/db_connection.ex:667: DBConnection.transaction/3
(ecto) lib/ecto/repo/schema.ex:124: Ecto.Repo.Schema.insert!/4
(elixir) lib/code.ex:363: Code.require_file/2
(mix) lib/mix/tasks/run.ex:71: Mix.Tasks.Run.run/1
(mix) lib/mix/task.ex:296: Mix.Task.run_task/3
任何人都知道我可能做错了什么?
更新
这是新的seeds.exs:
alias TestCms.Repo
alias TestCms.Show
alias TestCms.Episode
Repo.insert! Show.changeset(%Show{}, %{
title: "NP News",
position: 1,
showimageurl: %Plug.Upload{filename: "file.jpg", path: "http://test.tv/RokuImages/MusicVideoImages/Emerald_RokuHD.jpg"},
lcrshowimageurl: %Plug.Upload{filename: "file.jpg", path: "http://test.tv/RokuImages/MusicVideoImages/Emerald_RokuHD.jpg"},
shuffleepisodes: true
})
以下是我遇到的新错误:
** (Ecto.InvalidChangesetError) could not perform insert because changeset is invalid.
* Changeset changes
%{position: 1, shuffleepisodes: true, title: "NP News"}
* Changeset params
%{"lcrshowimageurl" => {%Plug.Upload{content_type: nil, filename: "file.jpg", path: "http://test.tv/RokuImages/MusicVideoImages/Emerald_RokuHD.jpg"}, %TestCms.Show{__meta__: #Ecto.Schema.Metadata<:built, "shows">, episodes: #Ecto.Association.NotLoaded<association :episodes is not loaded>, id: nil, inserted_at: nil, lcrshowimageurl: nil, position: 1, showimageurl: nil, shuffleepisodes: true, title: "NP News", updated_at: nil}}, "position" => 1, "showimageurl" => {%Plug.Upload{content_type: nil, filename: "file.jpg", path: "http://test.tv/RokuImages/MusicVideoImages/Emerald_RokuHD.jpg"}, %TestCms.Show{__meta__: #Ecto.Schema.Metadata<:built, "shows">, episodes: #Ecto.Association.NotLoaded<association :episodes is not loaded>, id: nil, inserted_at: nil, lcrshowimageurl: nil, position: 1, showimageurl: nil, shuffleepisodes: true, title: "NP News", updated_at: nil}}, "shuffleepisodes" => true, "title" => "NP News"}
* Changeset errors
[showimageurl: {"is invalid", [type: TestCms.ShowImageUploader.Type]}, lcrshowimageurl: {"is invalid", [type: TestCms.LcrShowImageUploader.Type]}]
(ecto) lib/ecto/repo/schema.ex:127: Ecto.Repo.Schema.insert!/4
(elixir) lib/code.ex:363: Code.require_file/2
(mix) lib/mix/tasks/run.ex:71: Mix.Tasks.Run.run/1
(mix) lib/mix/task.ex:296: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
(elixir) lib/code.ex:363: Code.require_file/2
这是Show模块:
defmodule TestCms.Show do
use TestCms.Web, :model
use Arc.Ecto.Schema
schema "shows" do
field :title, :string
field :position, :integer
field :showimageurl, TestCms.ShowImageUploader.Type
field :lcrshowimageurl, TestCms.LcrShowImageUploader.Type
field :shuffleepisodes, :boolean, default: false
has_many :episodes, TestCms.Episode
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:title, :position, :shuffleepisodes])
|> cast_attachments(params, [:showimageurl, :lcrshowimageurl])
|> validate_required([:title, :position, :showimageurl, :lcrshowimageurl, :shuffleepisodes])
|> unique_constraint(:position)
end
def search(query, search_term) do
from s in query,
where: fragment("similarity(?, ?) > ?", s.title, ^search_term, 0.1),
order_by: fragment("similarity(?, ?) DESC", s.title, ^search_term)
end
end