ActiveRecord :: SubclassNotFound

问题描述 投票:20回答:2

我正在尝试将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插件

ruby-on-rails ruby redmine
2个回答
69
投票

如果有人在这里绊倒,有两种方法可以解决问题

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

    self.inheritance_column = :_type_disabled
    

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


18
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.