在軌中如何生成唯一的鍵?非空的唯一鍵軌
我有說The backend will have a relational DB, with one table with the following schema: "user : string, password : string, count : int", with user enforced to be non-empty, a unique key.
一個規範這是否意味着如果我使用
rails generate scaffold UserModel user:string password:string count:int
唯一鍵會爲我生成?它會默認有一個非空的要求嗎?
或者我需要
rails generate scaffold UserModel user:string password:string count:int unique_key int
您不需要顯式聲明唯一鍵,遷移將在運行時自動創建它。另外你爲什麼要調用你的用戶模型 - 「UserModel」?你可以稱它爲「用戶」。所以'rails g scaffold用戶用戶:string password:string' – Andrei 2013-02-10 18:34:56