2017-02-10 44 views
3

我正在使用「Programming Phoenix」一書學習Phoenix。第一個項目創建了一個postgres數據庫,這是我們的遷移。我無法擺脫架構中時間戳的警告。Phoenix/Elixir - 時間戳不存在,擴展爲時間戳()

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。如果我到timestamps()它不抱怨,再架構改變timestamps

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 

,但書從未展示模型的架構是什麼樣的運行遷移後:

我得到這樣的警告。這應該是正確的,還是有其他東西可以解決這個問題? Ecto/Phoenix模式中的'時間戳'表示應該是什麼樣子?

回答

4

Elixir 1.4在調用導入的或本地定義的函數時帶有0個參數而沒有括號,因爲它含糊不清當它與您的函數具有相同名稱的局部變量時應該表示的含義,無括號的變量名稱。

[內核]警告如果變量作爲函數調用

Source

這本書可能尚未更新爲1.4藥劑還。菲尼克斯發電機進行了更新,添加括號in June 2016

+0

非常感謝!很高興知道發生了什麼,因爲我的谷歌搜索沒有幫助。 – smkarber