For some reason or another my Ruby on Rails application is telling me that it can't run migrations. I an unsure how to fix this. I created a table with no information by accident. I then tried to delete the migration file and the table that it created. When I try to run the migration command it gives me this error:
rails aborted!
Don't know how to build task 'db:migration' (see --tasks)
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/railties-5.0.0/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/railties-5.0.0/lib/rails/commands/rake_proxy.rb:10:in `run_rake_task'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'
/home/ubuntu/workspace/saasapp/bin/rails:9:in `require'
/home/ubuntu/workspace/saasapp/bin/rails:9:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/spring-1.7.2/bin/spring:49:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
/home/ubuntu/workspace/saasapp/bin/spring:15:in `require'
/home/ubuntu/workspace/saasapp/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)
Can someone please help me fix this issue. I need to remove the existing table so that I can create the correct one. It won't populate my schema file.
This is the error that I get when I run rake db:migrate
rake db:migrate
== 20170322214259 CreateProfiles: migrating ===================================
-- change_table(:profiles)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: Cannot add a NOT NULL column with default value NULL: ALTER TABLE "profiles" ADD "created_at" datetime NOT NULL
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in initialize'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:innew'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in prepare'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:137:inexecute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in block in execute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:inblock in log'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in instrument'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:inlog'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in execute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:inadd_column'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:373:in add_column'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:1096:inadd_timestamps'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:525:in timestamps'
/home/ubuntu/workspace/saasapp/db/migrate/20170322214259_create_profiles.rb:11:inblock in change'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:443:in change_table'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:inblock in method_missing'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in block in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:insay_with_time'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in method_missing'
/home/ubuntu/workspace/saasapp/db/migrate/20170322214259_create_profiles.rb:3:inchange'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in exec_migration'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:inblock (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in block in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:inwith_connection'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:inblock in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in block in transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:inwithin_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:intransaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:inexecute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in block in migrate_without_lock'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:ineach'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in migrate_without_lock'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1133:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in up'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:inblock (2 levels) in '
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/rake-12.0.0/exe/rake:27:in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/bin/ruby_executable_hooks:15:ineval'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/bin/ruby_executable_hooks:15:in <main>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: Cannot add a NOT NULL column with default value NULL: ALTER TABLE "profiles" ADD "created_at" datetime NOT NULL
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:ininitialize'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in new'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:inprepare'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:137:in execute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:inblock in execute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:in block in log'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:ininstrument'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:in log'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:inexecute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:in add_column'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:373:inadd_column'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:1096:in add_timestamps'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:525:intimestamps'
/home/ubuntu/workspace/saasapp/db/migrate/20170322214259_create_profiles.rb:11:in block in change'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:443:inchange_table'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in block in method_missing'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:inblock in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:inmethod_missing'
/home/ubuntu/workspace/saasapp/db/migrate/20170322214259_create_profiles.rb:3:in change'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:inexec_migration'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:inblock in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:inblock in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:inblock in transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:intransaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:inddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:inblock in migrate_without_lock'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in each'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:inmigrate_without_lock'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1133:in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:inup'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/rake-12.0.0/exe/rake:27:in'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/bin/ruby_executable_hooks:15:in eval'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/bin/ruby_executable_hooks:15:in'
SQLite3::SQLException: Cannot add a NOT NULL column with default value NULL
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in initialize'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:innew'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in prepare'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:137:inexecute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in block in execute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:inblock in log'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in instrument'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:inlog'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:232:in execute'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:inadd_column'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:373:in add_column'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:1096:inadd_timestamps'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:525:in timestamps'
/home/ubuntu/workspace/saasapp/db/migrate/20170322214259_create_profiles.rb:11:inblock in change'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:443:in change_table'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:inblock in method_missing'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in block in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:insay_with_time'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in method_missing'
/home/ubuntu/workspace/saasapp/db/migrate/20170322214259_create_profiles.rb:3:inchange'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in exec_migration'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:inblock (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in block in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:inwith_connection'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:inblock in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in block in transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:inwithin_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:intransaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:inexecute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in block in migrate_without_lock'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:ineach'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in migrate_without_lock'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1133:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in up'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:inmigrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in migrate'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:inblock (2 levels) in '
/usr/local/rvm/gems/ruby-2.3.0#saasapp/gems/rake-12.0.0/exe/rake:27:in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/bin/ruby_executable_hooks:15:ineval'
/usr/local/rvm/gems/ruby-2.3.0#saasapp/bin/ruby_executable_hooks:15:in `'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
In addition to my comment suggesting you use rake db:migrate instead of rake db:migration:
I also suggest you look into rake db:rollback if you find you've made a mistake while generating your model/migration.
I believe you've used migration instead of migrate
rake db:migrate
Related
I am unable to create tables (i.e. run db:migrate successfully) in Rail 6 on Windows 7.
Just in case I completely reinstalled rails by Installing Ruby 2.6 development pack and doing a 'gem install rails' which for me installed Rails 6.0.3.1
I created a new project and the first thing did was generate a 'Customer' model after which I ran the db:migrate command immediately after it failed saying the 'wrong number of arguments were given'. See below.
C:\Apps\rails>cd cmdb
C:\Apps\rails\cmdb>rails generate model Customer string:name
invoke active_record
create db/migrate/20200525080817_create_customers.rb
create app/models/customer.rb
invoke test_unit
create test/models/customer_test.rb
create test/fixtures/customers.yml
C:\Apps\rails\cmdb>rails db:migrate
== 20200525080817 CreateCustomers: migrating ==================================
-- create_table(:customers)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (given 1, expected 0)
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:4:in `block in change'
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:3:in `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:4:in `block in change'
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:3:in `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
The migration.rb was generated and is shown below:-
class CreateCustomers < ActiveRecord::Migration[6.0]
def change
create_table :customers do |t|
t.name :string
t.timestamps
end
end
end
The re-run with a full trace is pasted below:-
C:\Apps\rails\cmdb>rails db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
== 20200525080817 CreateCustomers: migrating ==================================
-- create_table(:customers)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (given 1, expected 0)
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:4:in `block in change'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:309:in `create_table'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:890:in `block in method_missing'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:858:in `block in say_with_time'
C:/Ruby26-x64/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:858:in `say_with_time'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:879:in `method_missing'
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:3:in `change'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:828:in `exec_migration'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:812:in `block (2 levels) in migrate'
C:/Ruby26-x64/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:811:in `block in migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:471:in `with_connection'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:810:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1002:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1310:in `block in execute_migration_in_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1361:in `block in ddl_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `block in tra
nsaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_
transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in
synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchroniz
e'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transacti
on'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:212:in `transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1361:in `ddl_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1309:in `execute_migration_in_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1281:in `block in migrate_without_lock'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1280:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1280:in `migrate_without_lock'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1231:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1061:in `up'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1036:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <top (required)>'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:84:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <top (required)>'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
C:/Ruby26-x64/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/command.rb:48:in `invoke'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:4:in `block in change'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:309:in `create_table'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:890:in `block in method_missing'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:858:in `block in say_with_time'
C:/Ruby26-x64/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:858:in `say_with_time'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:879:in `method_missing'
C:/Apps/rails/cmdb/db/migrate/20200525080817_create_customers.rb:3:in `change'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:828:in `exec_migration'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:812:in `block (2 levels) in migrate'
C:/Ruby26-x64/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:811:in `block in migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:471:in `with_connection'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:810:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1002:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1310:in `block in execute_migration_in_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1361:in `block in ddl_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `block in tra
nsaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_
transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in
synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchroniz
e'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transacti
on'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:212:in `transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1361:in `ddl_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1309:in `execute_migration_in_transaction'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1281:in `block in migrate_without_lock'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1280:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1280:in `migrate_without_lock'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1231:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1061:in `up'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/migration.rb:1036:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <top (required)>'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:84:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <top (required)>'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
C:/Ruby26-x64/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/command.rb:48:in `invoke'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
C:\Apps\rails\cmdb>
In case anyone else is wondering why else this could be:
I generated a migration with the same name as my model and started to get TypeError: superclass mismatch for class MyCustomClassName error. Then I renamed the migration class to CreateMyCustomClassNameTable but left its file name the same 20201217095257_my_custom_class_name.rb which produced ArgumentError: wrong number of arguments (given 2, expected 0..1) error. Renaming file to 20201217095257_create_my_custom_class_name_table.rb fixes the problem for me.
You have generated migration wrongly.
The column name comes first and it's data type follows it. Compare following with the command you used.
rails generate model Customer name:string
You can quickly fix it by running
rails destroy model Customer
and then re generate migration using the generate command I shared above.
I recently ran into a similar issue, below is the error that I got:
-- create_table(:workers)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
wrong number of arguments (given 1, expected 0)
/home/wint3r/Learn/RubyOnRails/AssetManager/db/migrate/20210516062205_create_workers.rb:9:in `block in change'
/home/wint3r/Learn/RubyOnRails/AssetManager/db/migrate/20210516062205_create_workers.rb:3:in `change'
/home/wint3r/Learn/RubyOnRails/AssetManager/bin/rails:5:in `<top (required)>'
/home/wint3r/Learn/RubyOnRails/AssetManager/bin/spring:10:in `block in <top (required)>'
/home/wint3r/Learn/RubyOnRails/AssetManager/bin/spring:7:in `<top (required)>'
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
/home/wint3r/Learn/RubyOnRails/AssetManager/db/migrate/20210516062205_create_workers.rb:9:in `block in change'
/home/wint3r/Learn/RubyOnRails/AssetManager/db/migrate/20210516062205_create_workers.rb:3:in `change'
/home/wint3r/Learn/RubyOnRails/AssetManager/bin/rails:5:in `<top (required)>'
/home/wint3r/Learn/RubyOnRails/AssetManager/bin/spring:10:in `block in <top (required)>'
/home/wint3r/Learn/RubyOnRails/AssetManager/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:migrate
In my case issue occurred because I tried to use t.timestamps for a custom datetime field 'emp_joining_date', I solved it by changing the type from t.timestamps to t.datetime
I am had Paperclip gem in my app then I removed it and I wanna add it back again. However, I am getting this error when I try to rake db:migrate:
ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to AddAttachmentImageToPosts (20170115210207)
(0.3ms) BEGIN
== 20170115210207 AddAttachmentImageToPosts: migrating ========================
-- change_table(:posts)
(0.9ms) ALTER TABLE "posts" ADD "image_file_name" character varying
(0.2ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateColumn: ERROR: column "image_file_name" of relation "posts" already exists
: ALTER TABLE "posts" ADD "image_file_name" character varying
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/schema_statements.rb:423:in `add_column'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_definitions.rb:443:in `column'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:54:in `block (2 levels) in attachment'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:52:in `each_pair'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:52:in `block in attachment'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:51:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:51:in `attachment'
/home/ubuntu/workspace/db/migrate/20170115210207_add_attachment_image_to_posts.rb:4:in `block in up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:363:in `change_table'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in `method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:416:in `method_missing'
/home/ubuntu/workspace/db/migrate/20170115210207_add_attachment_image_to_posts.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:571:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:611:in `exec_migration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
ActiveRecord::StatementInvalid: PG::DuplicateColumn: ERROR: column "image_file_name" of relation "posts" already exists
: ALTER TABLE "posts" ADD "image_file_name" character varying
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/schema_statements.rb:423:in `add_column'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_definitions.rb:443:in `column'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:54:in `block (2 levels) in attachment'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:52:in `each_pair'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:52:in `block in attachment'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:51:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:51:in `attachment'
/home/ubuntu/workspace/db/migrate/20170115210207_add_attachment_image_to_posts.rb:4:in `block in up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:363:in `change_table'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in `method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:416:in `method_missing'
/home/ubuntu/workspace/db/migrate/20170115210207_add_attachment_image_to_posts.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:571:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:611:in `exec_migration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
PG::DuplicateColumn: ERROR: column "image_file_name" of relation "posts" already exists
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/schema_statements.rb:423:in `add_column'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_definitions.rb:443:in `column'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:54:in `block (2 levels) in attachment'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:52:in `each_pair'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:52:in `block in attachment'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:51:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/paperclip-5.1.0/lib/paperclip/schema.rb:51:in `attachment'
/home/ubuntu/workspace/db/migrate/20170115210207_add_attachment_image_to_posts.rb:4:in `block in up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:363:in `change_table'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in `method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:416:in `method_missing'
/home/ubuntu/workspace/db/migrate/20170115210207_add_attachment_image_to_posts.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:571:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:611:in `exec_migration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
When I ran rails c this is what I got:
2.3.0 :001 > Post.column_names
=> ["id", "title", "link", "description", "created_at", "updated_at", "user_id", "image_file_name", "image_content_type", "image_file_size", "image_updated_at", "cached_votes_total", "cached_votes_score", "cached_votes_up", "cached_votes_down", "cached_weighted_score", "cached_weighted_total", "cached_weighted_average", "image"]
I know that there is a way to remove the "image_file_name" duplication but I am not really aware of how to do so to my app. I did find some posts that are similar to my problem but nothing really solved it!
Because you deleted the migration for creating the column, and if you create a migration to delete it, it will cause error in other environment(production), as there is no column to be deleted at first place.
Assuming you haven't deploy the migration to production.
You can just drop the column directly in database console.
run rails dbconsole
and
ALTER TABLE posts DROP COLUMN image_file_name;
First of all, you should never just remove a migration. If you want to remove a field you should create a new migration for it.
You have 2 options now, or you can rake db:migration:reset that will recreate your entire database OR you can comment the content on this last migration, run rake db:migrate and after that you can uncomment it.
I've been following the tutorial "Multitenancy with Rails" by Ryan Bigg https://leanpub.com/multi-tenancy-rails.
Though I have run rake db:migrate I keep getting an error Migrations are pending. To resolve this issue run bin/rake db:migrate RAILS_ENV=test
If I do that I get another set of errors.
Since I don't have enough reputation, I can't post the images here.
If anyone has seen the book, I'm getting the error after adding the add_owner_id_to_accounts migration.
Any help would be really appreciated. Thanks!
This is the error I am getting:
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:392:in `check_pending!': (ActiveRecord::PendingMigrationError)
Migrations are pending. To resolve this issue, run:
bin/rake db:migrate RAILS_ENV=test
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:405:in `load_schema_if_pending!'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:411:in `block in maintain_test_schema!'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:639:in `suppress_messages'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:416:in `method_missing'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:411:in `maintain_test_schema!'
from /home/nikhil/workspace2/subscribem/spec/rails_helper.rb:29:in `<top (required)>'
from /home/nikhil/workspace2/subscribem/spec/features/accounts/sign_up_spec.rb:1:in `require'
from /home/nikhil/workspace2/subscribem/spec/features/accounts/sign_up_spec.rb:1:in `<top (required)>'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1327:in `load'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1325:in `each'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:102:in `setup'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:88:in `run'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:73:in `run'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:41:in `invoke'
from /home/nikhil/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/exe/rspec:4:in `<top (required)>'
from /home/nikhil/.rvm/gems/ruby-2.2.2/bin/rspec:23:in `load'
from /home/nikhil/.rvm/gems/ruby-2.2.2/bin/rspec:23:in `<main>'
from /home/nikhil/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
from /home/nikhil/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
And this is what I'm getting if I run rake db:migrate RAILS_ENV=test(as the output asks me to)
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/railties-4.2.3/lib/rails/tasks/statistics.rake:4: warning: already initialized constant STATS_DIRECTORIES
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/railties-4.2.3/lib/rails/tasks/statistics.rake:4: warning: previous definition of STATS_DIRECTORIES was here
== 20150627112900 CreateSubscribemAccounts: migrating =========================
-- create_table(:subscribem_accounts)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "subscribem_accounts" already exists: CREATE TABLE "subscribem_accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:208:in `create_table'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:661:in `block in method_missing'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `block in say_with_time'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `say_with_time'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:651:in `method_missing'
/home/nikhil/workspace2/subscribem/db/migrate/20150627112900_create_subscribem_accounts.rb:3:in `change'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:605:in `exec_migration'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:589:in `block (2 levels) in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:588:in `block in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:587:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:764:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:994:in `block in execute_migration_in_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:1040:in `block in ddl_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/transactions.rb:220:in `transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:1040:in `ddl_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:993:in `execute_migration_in_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:955:in `block in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:951:in `each'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:951:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:819:in `up'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:797:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "subscribem_accounts" already exists: CREATE TABLE "subscribem_accounts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:208:in `create_table'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:661:in `block in method_missing'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `block in say_with_time'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `say_with_time'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:651:in `method_missing'
/home/nikhil/workspace2/subscribem/db/migrate/20150627112900_create_subscribem_accounts.rb:3:in `change'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:605:in `exec_migration'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:589:in `block (2 levels) in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:588:in `block in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:587:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:764:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:994:in `block in execute_migration_in_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:1040:in `block in ddl_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/transactions.rb:220:in `transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:1040:in `ddl_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:993:in `execute_migration_in_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:955:in `block in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:951:in `each'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:951:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:819:in `up'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:797:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
SQLite3::SQLException: table "subscribem_accounts" already exists
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `block in execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in `execute'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:208:in `create_table'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:661:in `block in method_missing'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `block in say_with_time'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:631:in `say_with_time'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:651:in `method_missing'
/home/nikhil/workspace2/subscribem/db/migrate/20150627112900_create_subscribem_accounts.rb:3:in `change'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:605:in `exec_migration'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:589:in `block (2 levels) in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:588:in `block in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:587:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:764:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:994:in `block in execute_migration_in_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:1040:in `block in ddl_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/transactions.rb:220:in `transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:1040:in `ddl_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:993:in `execute_migration_in_transaction'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:955:in `block in migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:951:in `each'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:951:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:819:in `up'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/migration.rb:797:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/nikhil/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate => app:db:migrate
(See full trace by running task with --trace)
In test_helper.rb -
ActiveRecord::Migration.maintain_test_schema!
This maintains your test database every time, whenever you run your tests.
It seem that the source of problem is here :
SQLite3::SQLException: table "subscribem_accounts" already exists
subscribem_accounts table seem already existing, and it's like you're trying to create it twice, so try to reset the database :
rake db:reset
this command will drop your actual database, and recreate it again for you
I have been having some issues with rake db:migrate while setting up a pins scaffold for the One Mont Rails tutorial. When I try to migrate in the terminal I get the following error:
Taylors-MacBook-Pro:pinteresting taylorburton$ bin/rake db:migrate RAILS_ENV=development
== 20150410031405 AddUserIdToPins: migrating ==================================
-- add_column(:pins, :user_id, :integer)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: user_id: ALTER TABLE "pins" ADD "user_id" integer/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:333:in `block in execute'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598#global/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:333:in `execute'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:381:in `add_column'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:458:in `add_column'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:662:in `block in method_missing'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `block in say_with_time'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `say_with_time'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:652:in `method_missing'
/Users/taylorburton/Desktop/pinteresting/db/migrate/20150410031405_add_user_id_to_pins.rb:3:in `change'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:606:in `exec_migration'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:589:in `block in migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:588:in `migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:765:in `migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598#global/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598#global/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598#global/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/taylorburton/.rvm/gems/ruby-2.0.0-p598#global/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Taylors-MacBook-Pro:pinteresting taylorburton$
Read the error message carefully. It says:
duplicate column name: user_id: ALTER TABLE "pins" ADD "user_id"
This means user_id is already present in pins table when your migration is being carried out, which was unexpected. Hence the error.
If you drop user_id column from pins table this error will go and hopefully migration will succeed. However manually (by this I mean using SQL commands) altering Rails database is not recommended and in fact that itself is very likely to be the reason behind this error in first place.
Alternatively, if you dont care about any existing data, you can also do:
rake db:reset
Followed by rake db:migrate
I guess this is another reason I should be backing up my work with GitHub, but alas, I have not been.
The migration I want to rollback is this:
class AddAssociationToTables < ActiveRecord::Migration
def change
add_column :articles, :user, :belongs_to
end
end
Which obviously isn't well formed because it seems to have totally removed my article table from the database.
I tried rake db:rollback:status and there is nothing 'missing' or anything.
I'm gonna skip copy-pasting the entire trace.
I tried to make a counteracting migration and run that. This is what I wrote:
class RemoveAssociationFromArticle < ActiveRecord::Migration
def change
remove_column :articles, :user, :belongs_to
end
end
But when I tried to run rake db:migrate with this I got what looks like the same error.
EDIT ok here's the whole trace for the rollback first, and then the migrate attempt
== AddAssociationToTables: reverting =========================================
-- remove_column(:articles, :user, :belongs_to)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `to_sym' for nil:NilClass/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:215:in `column'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:545:in `block (2 levels) in copy_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:538:in `each'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:538:in `block in copy_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:184:in `create_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:535:in `copy_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:528:in `move_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:521:in `block in alter_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:200:in `transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:520:in `alter_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:463:in `remove_column'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:625:in `block in method_missing'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:597:in `block in say_with_time'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:597:in `say_with_time'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:617:in `method_missing'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:462:in `block in revert'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:461:in `each'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:461:in `revert'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:569:in `exec_migration'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:555:in `block (2 levels) in migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:554:in `block in migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:553:in `migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:709:in `migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/transactions.rb:209:in `transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:1005:in `ddl_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:920:in `block in migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `each'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:771:in `down'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:857:in `move'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:753:in `rollback'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:126:in `block (2 levels) in <top (required)>'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:rollback
(See full trace by running task with --trace)
== RemoveAssociationFromArticle: migrating ===================================
-- remove_column(:articles, :user, :belongs_to)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `to_sym' for nil:NilClass/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:215:in `column'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:545:in `block (2 levels) in copy_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:538:in `each'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:538:in `block in copy_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:184:in `create_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:535:in `copy_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:528:in `move_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:521:in `block in alter_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:200:in `transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:520:in `alter_table'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:463:in `remove_column'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:625:in `block in method_missing'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:597:in `block in say_with_time'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:597:in `say_with_time'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:617:in `method_missing'
/home/macs/code/my_apps/rails_apps/satisfactory/dec1/whatis/db/migrate/20131202144933_remove_association_from_article.rb:3:in `change'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:571:in `exec_migration'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:555:in `block (2 levels) in migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:554:in `block in migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:553:in `migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:709:in `migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/transactions.rb:209:in `transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:1005:in `ddl_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:920:in `block in migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `each'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:764:in `up'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/migration.rb:742:in `migrate'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval'
/home/macs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
The third parameter should be the type of column.
The correct syntax is:
add_column :articles, :user_id, :integer
The :belongs_to parameter may causing conflict with ActiveRecord methods!
If it did not migrate properly in the first place, don't worry about rolling back. Just fix the migration and try to migrate again.
Your migration should be:
add_column :articles, :user, :references
The belongs_to is for in the model class, and not in the migration. If it gets to a point where you can't do anything, you can always recreate the database to start fresh (and lose all data).
$ rake db:drop db:create db:migrate
Start using version control, and read through all of this slowly and carefully at some point in life http://guides.rubyonrails.org/migrations.html