的ActiveRecord :: SubclassNotFound

时间:2012-07-13 11:55:05

标签: ruby-on-rails ruby redmine

我正在尝试将我的redmine从1.3.0升级到2.0.0,但是我在数据库迁移方面遇到了问题。当我运行命令时:

rake db:migrate RAILS_ENV=production

它显示错误,如

rake aborted!
uninitialized constant RAILS_ENV

我的错误日志是:

ActiveRecord::SubclassNotFound (The single-table inheritance mechanism failed to locate the subclass: 'GoogleAppsAuthSource'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite AuthSource.inheritance_column to use another column for that information.):
app/models/user.rb:139:in `try_to_login'
app/controllers/account_controller.rb:143:in `password_authentication'
app/controllers/account_controller.rb:138:in `authenticate_user'
app/controllers/account_controller.rb:30:in `login'

以下是我在旧版redmine中使用的插件列表:

  1. Google Apps插件

  2. Redmine Code Review插件

  3. Redmine Hudson插件

  4. 请帮帮我

2 个答案:

答案 0 :(得分:67)

如果其他人在这里遇到障碍,有两种方法可以解决问题

  1. 不要使用名为type的列。
  2. 手动将列名设置为无意义的内容:

    self.inheritance_column = :_type_disabled
    

    请参阅:http://apidock.com/rails/ActiveRecord/Base/inheritance_column/class

答案 1 :(得分:17)

单表继承错误可能是由数据库中名为type的列引起的。

如果rails遇到名为type的列名,则假定它是一个具有子类的模型,因此该类型可以区分要使用的模型。我想一些最初不是为rails构建的插件在它的模型中使用了type列,导致Rails失败。