【发布时间】:2017-02-10 13:03:16
【问题描述】:
我正在使用“Programming Phoenix”一书学习 Phoenix。第一个项目创建了一个 postgres 数据库,这是我们的迁移。我无法摆脱架构中的时间戳警告。
defmodule Rumbl.Repo.Migrations.CreateUser do
use Ecto.Migration
def change do
create table(:users) do
add :name, :string
add :username, :string, null: false
add :password_hash, :string
timestamps
end
create unique_index(:users, [:username])
end
end
那么我们这次迁移对应的模型是:
defmodule Rumbl.User do
use Rumbl.Web, :model
schema "users" do
field :name, :string
field :username, :string
field :password, :string, virtual: true
field :password_hash, :string
timestamps
end
end
现在我运行迁移,然后是 mix phoenix.server。
我收到了这个警告:
warning: variable "timestamps" does not exist and is being expanded to "timestamps()",
please use parentheses to remove the ambiguity or change the variable name
web/models/user.ex:10
如果我将架构中的timestamps 更改为timestamps(),它不会再抱怨了,但是这本书从未显示运行迁移后模型的架构是什么样子。这应该是正确的,还是有其他方法可以解决这个问题? Ecto/Phoenix 模式中的“时间戳”表示应该是什么样子?
【问题讨论】:
标签: postgresql elixir phoenix-framework ecto