smk*_*ber 4 postgresql elixir ecto phoenix-framework
我正在使用"编程凤凰"这本书学习凤凰.第一个项目创建了一个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
Run Code Online (Sandbox Code Playgroud)
那么我们对应这个迁移的模型是:
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
Run Code Online (Sandbox Code Playgroud)
现在我运行迁移,然后是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
Run Code Online (Sandbox Code Playgroud)
如果我timestamps将模式更改为timestamps()不再抱怨,但本书从未显示运行迁移后模型的模式.这应该是正确的,还是有其他东西可以解决这个问题?Ecto/Phoenix模式中的'timestamps'表示应该是什么样的?
| 归档时间: |
|
| 查看次数: |
606 次 |
| 最近记录: |