Binu Paul Binu Paul - 1 year ago 52
Ruby Question

Ruby on rails - active record migration issue

The command bin/rails db:migrate is throwing error as given below:

---
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)
---


The structure of the migration table is:

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

t.timestamps
end
end
end

Answer Source

I see your using a gem called activerecord-mysql2-adapter and by the seems of it, it's not using the type_to_sql method correctly in rails 5.1 ActiveRecord. My suggestion would be to change your gem from activerecord-mysql2-adapter, to just be mysql2 unless there is a specific reason your using that gem in particular.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download