【发布时间】:2015-03-24 12:32:33
【问题描述】:
我正在使用一个预先存在的数据库,其中用户数据的表是 t_customer。为了遵守 Rails 约定,我将关联模型命名为“User”
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
self.table_name = "t_customer"
self.primary_key = "cust_id"
end
然后我运行 rails generate devise User,然后运行 rake db:migrate,但 rake 因错误而中止
UndefinedTable:错误:关系“用户”不存在
我该如何解决?这是错误的方法吗?在创建用户模型之后,但在创建设计迁移之前,我是否应该运行 rake db:migrate 或类似的东西?我不知道如何让 rails 知道 :users 是指迁移文件中的 t_customer 表:
class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
【问题讨论】:
标签: ruby-on-rails database devise