0
我有一項用戶模式添加列,制定用戶表
class DeviseCreateUsers < ActiveRecord::Migration
def change
...
end
end
我想這些列添加到模型中。我想我可能會將自己與Rails所做的自動複數相混淆。
當我使用命令rails g migration AddDetailsToUsers
,我在change
方法中添加了以下代碼。
class AddDetailsToUsers < ActiveRecord::Migration
def change
add_column :Users, :username, :string
add_column :Users, :firstname, :string
add_column :Users, :lastname, :string
add_column :Users, :billing_address, :string
add_column :Users, :credit_card, :string
add_column :Users, :total_earned, :string
add_column :Users, :home_address, :string
add_column :Users, :leeway_time, :string
end
ends
我也rake db:migrate
嘗試更新數據庫,我得到
== 20141012065730 AddDetailsToUsers: migrating ================================
-- add_column(:Users, :username, :string)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "Users" does not exist
我嘗試看看我是否能與此表中的'軌道ç
User.first
User Load (0.9ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
=> nil
感謝您的幫助!該命令得到了比以前更進一步,但現在這個錯誤顯示NameError:未初始化的常量AddDetailsToUserup'' – Liondancer 2014-10-12 08:10:49
可能有一個錯字。你能否顯示已更改的遷移文件? – Santhosh 2014-10-12 08:24:24
http://pastebin.com/FdUmcNcx在這裏你去!謝謝! – Liondancer 2014-10-12 08:37:32