设计迁移不起作用
我使用 Devise
创建了一个用户模型,每当我使用 rake db:migrate
时,我都会遇到以下问题:
== DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `database_authenticatable' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000103fa1ff0>
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我使用 --trace function< 运行完整跟踪/code> 但似乎无法弄清楚问题是什么。 这是迁移文件:
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.confirmable
# t.encryptable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
def self.down
drop_table :users
end
end
I created a User model using Devise
and whenever I use rake db:migrate
I get the following issue:
== DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `database_authenticatable' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000103fa1ff0>
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I run the full trace with the --trace function
but can't seem to figure out what the issue is.
Here is the migration file:
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.confirmable
# t.encryptable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
def self.down
drop_table :users
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Devise 2.0 消除了用于创建数据库表的辅助函数:
https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style
所以你需要的是:
Devise 2.0 eliminated helper functions for creating the database tables:
https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style
So what you need is:
很高兴听到。
我想官方答案是重新运行这些步骤:
rails g devise:install
rails g devise user
rake db:migrate
rails s
// 循环你的服务器以防万一...Good to hear.
I guess the official answer would be to rerun the steps:
rails g devise:install
rails g devise user
rake db:migrate
rails s
// cycle your server just in case...