【问题标题】:rails pg db migration undefined method `database_authenticatable' for Devise Users设计用户的rails pg db迁移未定义方法“database_authenticable”
【发布时间】:2015-07-20 22:41:29
【问题描述】:

undefined method database_authenticatable' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0xd715388>

迁移是:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable
      t.timestamps
    end
    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
  end
  def self.down
    drop_table :users
  end
end

【问题讨论】:

标签: ruby-on-rails ruby postgresql pg


【解决方案1】:

如果我没记错的话,设计改变它从

生成的迁移样式
create_table(:user) do |t|
  t.database_authenticatable
end

到

create_table(:user) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""
end

2.0 版之后。

更新:见wiki。

【讨论】:

  • +1 有用。但是如果这是一个现有的 Rails 应用程序并且用户迁移是早期的应用程序之一,那么正确的方法是什么?我应该编辑吗?删除它并重做一个全新的?进行迁移以删除旧的,添加新的?这些问题的正确答案将帮助我找到一个好的解决方案
  • 我检查了上面的 wiki 参考 - github.com/plataformatec/devise/wiki/… - 它很有帮助,例如“您需要将原始的 Devise 迁移更改为不使用 Before 帮助程序,而是使用列出的字段...”
  • 也许把wiki的更新链接放在这篇文章的顶部而不是底部?
【解决方案2】:

这对我有用:

create_table(:users) do |t|
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""
  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  # t.encryptable
  # t.confirmable
  # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
  # t.token_authenticatable


  t.timestamps
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-14
    • 2017-01-11
    • 1970-01-01
    • 2011-02-14
    • 2019-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多