我有一个设计用户模型
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
我试着看看我是否可以在`rails c
中使用这个表 User.first
User Load (0.9ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
=> nil
答案 0 :(得分:1)
表名称区分大小写。将所有出现的:Users
更改为迁移文件中的:users
例如:
add_column :users, :username, :string
add_column :users, :firstname, :string
..