elight / acts_as_commentable_with_threading

Similar to acts_as_commentable; however, utilizes awesome_nested_set to provide threaded comments
MIT License
672 stars 167 forks source link

migration fail in rails 5.1.z #111

Open buncis opened 7 years ago

buncis commented 7 years ago
StandardError: An error has occurred, this and all later migrations canceled:

Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

  class ActsAsCommentableWithThreadingMigration < ActiveRecord::Migration[4.2]
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:525:in `inherited'
/home/user/lazy-api/db/migrate/20170808131454_acts_as_commentable_with_threading_migration.rb:1:in `<top (required)>'
/home/user/.rvm/gems/ruby-2.2.6/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/home/user/.rvm/gems/ruby-2.2.6/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
/home/user/.rvm/gems/ruby-2.2.6/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
/home/user/.rvm/gems/ruby-2.2.6/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:962:in `load_migration'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:958:in `migration'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:953:in `disable_ddl_transaction'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1305:in `use_transaction?'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1297:in `ddl_transaction'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1200:in `each'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1150:in `migrate'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:1007:in `up'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/migration.rb:985:in `migrate'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/home/user/.rvm/gems/ruby-2.2.6/gems/activerecord-5.1.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/home/user/.rvm/gems/ruby-2.2.6/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/user/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `eval'
/home/user/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `<main>'

I need to add the migration version [5.1] to fix this

class ActsAsCommentableWithThreadingMigration < ActiveRecord::Migration[5.1]
  def self.up
    create_table :comments, :force => true do |t|
      t.integer :commentable_id
      t.string :commentable_type
      t.string :title
      t.text :body
      t.string :subject
      t.integer :user_id, :null => false
      t.integer :parent_id, :lft, :rgt
      t.timestamps
    end

    add_index :comments, :user_id
    add_index :comments, [:commentable_id, :commentable_type]
  end

  def self.down
    drop_table :comments
  end
end
Kerzzi commented 6 years ago

I have the same question . Thank you.