我在 Ecto 项目中遇到了这个问题。没有一个查询有效。我做了一些谷歌搜索和 github 问题搜索。很少但与我的问题无关。
这个问题是从这个https://github.com/elixir-lang/ecto/issues/602#issuecomment-145596702开始的(主要与我的问题有关)
query = from u in Univer, where: u.id > 4, select: u
炸毁** (RuntimeError) undefined function: u/0
。不仅是那个模型,其他模型也是如此。我的部门。
{:postgrex, "~> 0.9.1"},
{:poison, "~> 1.5"},
{:httpoison, "~> 0.7.2"},
{:ecto, "~> 1.0.4"},
{:floki, "~> 0.5"}
目前从 db 读取的所有内容都是通过psql
. 它可以完成工作,但很烦人。:)
供参考。
defmodule Univer do
use Ecto.Model
import Ecto.Query
schema "univers" do
field :ref, :integer
field :name, :string
field :legal_name, :string
field :city, :string
field :type, :string
field :address, :string
field :contacts, {:array, :string}
field :fax, :string
field :phones, {:array, :string}
field :email, :string
field :url, :string
has_many :schools, School
has_one :place, Place
timestamps
end
end
和迁移
defmodule Univer.Repo.Migrations.AddUniversTable do
use Ecto.Migration
def up do
create table(:univers) do
add :ref, :integer
add :name, :text
add :legal_name, :text
add :type, :string
add :fax, :string
add :city, :string
add :contacts, {:array, :string}
add :address, :text
add :phones, {:array, :string}
add :email, :string
add :url, :string
timestamps
end
end
def down do
drop table(:univers)
end
end