Phoenix/Elixir - 时间戳不存在,扩展为 timestamps()
Phoenix/Elixir - timestamps does not exist, expanding to timestamps()
我正在使用本书 '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 模式中的 'timestamps' 表示应该是什么样的?
Elixir 1.4 添加了一个关于使用 0 个参数不带括号调用导入或本地定义的函数的警告,因为当你有一个与函数同名的局部变量并且你写不带括号的变量名。
[Kernel] Warn if variable is used as a function call
这本书可能还没有针对 Elixir 1.4 进行更新。 Phoenix 生成器已更新以添加括号 in June 2016.
我正在使用本书 '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 模式中的 'timestamps' 表示应该是什么样的?
Elixir 1.4 添加了一个关于使用 0 个参数不带括号调用导入或本地定义的函数的警告,因为当你有一个与函数同名的局部变量并且你写不带括号的变量名。
[Kernel] Warn if variable is used as a function call
这本书可能还没有针对 Elixir 1.4 进行更新。 Phoenix 生成器已更新以添加括号 in June 2016.