簡體   English   中英

使用不同的表名將設計添加到用戶模型

[英]adding devise to User model with different table name

我正在使用一個現有數據庫,其中用戶數據表為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或類似工具嗎? 我不知道如何使: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: ""

只需更改table_name

class AddDeviseToUsers < ActiveRecord::Migration
  def self.up
    change_table(:t_customer) do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM