Ruby on rails - 活动记录迁移问题

时间:2017-05-22 17:18:12

标签: ruby-on-rails ruby

命令bin / rails db:migrate正在抛出错误,如下所示:

---
rails aborted!
ArgumentError: wrong number of arguments (given 4, expected 1)
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1062:in `type_to_sql'
/var/lib/gems/2.3.0/gems/activerecord-mysql2-adapter-0.0.3/lib/active_record/connection_adapters/mysql2_adapter.rb:520:in `type_to_sql'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:17:in `type_to_sql'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:32:in `visit_ColumnDefinition'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:14:in `accept'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:45:in `block in visit_TableDefinition'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:45:in `map'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:45:in `visit_TableDefinition'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_creation.rb:14:in `accept'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:288:in `create_table'
/var/lib/gems/2.3.0/gems/activerecord-mysql2-adapter-0.0.3/lib/active_record/connection_adapters/mysql2_adapter.rb:439:in `create_table'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/schema_migration.rb:27:in `create_table'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1125:in `initialize'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1007:in `new'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1007:in `up'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:985:in `migrate'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/var/lib/gems/2.3.0/gems/activerecord-5.1.1/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.3.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/var/lib/gems/2.3.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/var/lib/gems/2.3.0/gems/railties-5.1.1/lib/rails/command.rb:46:in `invoke'
/var/lib/gems/2.3.0/gems/railties-5.1.1/lib/rails/commands.rb:16:in `<top (required)>'
/home/binu/workspace/ruby/demo/bin/rails:9:in `require'
/home/binu/workspace/ruby/demo/bin/rails:9:in `<top (required)>'
/var/lib/gems/2.3.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
/var/lib/gems/2.3.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
/var/lib/gems/2.3.0/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
/var/lib/gems/2.3.0/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
/var/lib/gems/2.3.0/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
/var/lib/gems/2.3.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
/var/lib/gems/2.3.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
/home/binu/workspace/ruby/demo/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
---

迁移表的结构是:

class CreateArticles < ActiveRecord::Migration[5.1]
  def change
    create_table :articles do |t|
      t.string :title
      t.text :description

      t.timestamps
    end
  end
end

1 个答案:

答案 0 :(得分:2)

我看到你使用了一个名为activerecord-mysql2-adapter的gem,看起来它没有在rails 5.1 ActiveRecord中正确使用type_to_sql方法。我的建议是将您的宝石从activerecord-mysql2-adapter更改为mysql2,除非您特别使用该宝石。