代码之家  ›  专栏  ›  技术社区  ›  Taryn East

rake db:migrate(+desert)正在给出“undefined method` abstract_class?”对象:类“

  •  1
  • Taryn East  · 技术社区  · 14 年前

    我只是想运行一个迁移,但是我得到了下面的stacktrace(如下)。

    我使用的是Rails 2.3.8和Desert 0.5.4。

    rake aborted!
    undefined method `abstract_class?' for Object:Class
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2242:in `class_of_active_record_descendant'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1492:in `base_class'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1164:in `reset_table_name'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1160:in `table_name'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:3154:in `quoted_table_name'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2261:in `sanitize_sql'
    /usr/lib/ruby/gems/1.8/gems/desert-0.5.4/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:24:in `send'
    /usr/lib/ruby/gems/1.8/gems/desert-0.5.4/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:24:in `initialize_schema_migrations_table'
    /usr/lib/ruby/gems/1.8/gems/desert-0.5.4/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:23:in `each'
    /usr/lib/ruby/gems/1.8/gems/desert-0.5.4/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:23:in `initialize_schema_migrations_table'
    /usr/lib/ruby/gems/1.8/gems/desert-0.5.4/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:12:in `each'
    /usr/lib/ruby/gems/1.8/gems/desert-0.5.4/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:12:in `initialize_schema_migrations_table'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/migration.rb:441:in `initialize'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/migration.rb:401:in `new'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/migration.rb:401:in `up'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/migration.rb:383:in `migrate'
    /usr/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/tasks/databases.rake:112
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
    /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
    /usr/bin/rake:19:in `load'
    /usr/bin/rake:19
    

    该bug出现在下面一行的沙漠宝石中:

    /usr/lib/ruby/gems/1.8/gems/desert-0.5.4/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:24
    

    结果是:

    insert_sql = ActiveRecord::Base.send(:sanitize_sql, [ "INSERT INTO... 
    

    有什么解决办法吗?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Taryn East    14 年前

    我有一个黑客绕过它,但它很难看:

    class Object
      # ActiveRecord::Base *is* an abstract class.
      unless defined?(abstract_class?)
        def abstract_class?
          true
        end
      end
    end