Error when adding a column with several options - ruby-on-rails

I have the following migration in the system I'm working on:
class CreateEstoqueGruposProdutos < ActiveRecord::Migration
def change
create_table :est_grupos_produtos do |t|
t.integer :grupos_produtos_nivel_id, :null => false, foreign_key: { references: :est_grupos_produtos_niveis, on_update: :cascade, on_delete: :restrict }, index: { with: [:id], unique: true, :name => 'unique_grupos_produtos_id_nivel' }
t.timestamps
end
end
end
It basically creates a table with an integer column that references (foreign_key) another table and add some options to the index.
Now, I need to do the same thing with a table that already exists. I need to add a column like this to a table with existing data.
I'm trying to do:
class ChangeCadastrosPerfilNiveis < ActiveRecord::Migration
def change
add_column :cad_perfil_niveis, :perfil_niveis_nivel_id, :integer, :null => false, :default => 1, foreign_key: { references: :cad_perfil_niveis_niveis, on_update: :cascade, on_delete: :restrict }, index: { with: [:id], unique: true, :name => 'unique_perfil_niveis_id_nivel' }
end
end
It's not working. The error output is:
-- add_column(:cad_perfil_niveis, :perfil_niveis_nivel_id, :integer, {:null=>false, :default=>1, :foreign_key=>{:references=>:cad_perfil_niveis_niveis, :on_update=>:cascade, :on_delete=>:restrict}, :index=>{:with=>[:id], :unique=>true, :name=>"unique_perfil_niveis_id_nivel"}})
rake aborted!
An error has occurred, this and all later migrations canceled:
wrong number of arguments (5 for 3)
Backtrace:
wrong number of arguments (5 for 3)
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/foreigner-1.1.6/lib/foreigner/connection_adapters/sql2003.rb:17:in `add_foreign_key'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/schema_plus-1.1.2/lib/schema_plus/active_record/column_options_handler.rb:24:in `schema_plus_handle_column_options'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/schema_plus-1.1.2/lib/schema_plus/active_record/foreign_keys.rb:125:in `add_column'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:450:in `block in method_missing'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:424:in `block in say_with_time'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:424:in `say_with_time'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:444:in `method_missing'
/home/sinetic/www/next/cadastros/db/migrate/20150223112512_change_cadastros_perfil_niveis.rb:4:in `change'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:393:in `block (2 levels) in migrate'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:393:in `block in migrate'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:118:in `with_connection'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:377:in `migrate'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:512:in `migrate'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:704:in `block (2 levels) in migrate'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:759:in `call'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:759:in `block in ddl_transaction'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/transactions.rb:208:in `transaction'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:759:in `ddl_transaction'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:703:in `block in migrate'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:684:in `each'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:684:in `migrate'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:554:in `up'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/migration.rb:535:in `migrate'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/home/sinetic/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547#global/gems/rake-0.9.2.2/bin/rake:32:in `<top (required)>'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/bin/rake:23:in `load'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/bin/rake:23:in `<main>'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/home/sinetic/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
How do this options could be added to the table in question without dropping it and creating it again?

Try to use change_table method:
change_table(:cad_perfil_niveis) do |t|
t.integer :perfil_niveis_nivel_id, :null => false, :default => 1, foreign_key: { references: :cad_perfil_niveis_niveis, on_update: :cascade, on_delete: :restrict }, index: { with: [:id], unique: true, :name => 'unique_perfil_niveis_id_nivel' }
end

Related

PG::UndefinedTable: ERROR: relation "user_profiles" does not exist when trying to run : heroku run rake db:migrate

I have created a web app in rails and I was using sqlite3. Now I am trying to deploy it with heroku which uses pg but I am running into this error:
PG::UndefinedTable: ERROR: relation "user_profiles" does not exist
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:92:in `exec'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:92:in `block (2 levels) in execute'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:91:in `block in execute'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `block (2 levels) in log'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:717:in `block in log'
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:708:in `log'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:90:in `execute'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/postgresql/schema_statements.rb:443:in `add_index'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:890:in `block in method_missing'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:858:in `block in say_with_time'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:858:in `say_with_time'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:879:in `method_missing'
/app/db/migrate/20200327044108_create_user_profiles.rb:10:in `block in change'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:309:in `create_table'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:890:in `block in method_missing'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:858:in `block in say_with_time'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:858:in `say_with_time'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:879:in `method_missing'
/app/db/migrate/20200327044108_create_user_profiles.rb:3:in `change'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:828:in `exec_migration'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:812:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:811:in `block in migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `with_connection'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:810:in `migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1001:in `migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1311:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1362:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:281:in `block in transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:281:in `transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/transactions.rb:212:in `transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1362:in `ddl_transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1310:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1282:in `block in migrate_without_lock'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1281:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1281:in `migrate_without_lock'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1229:in `block in migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1382:in `with_advisory_lock'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1229:in `migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1061:in `up'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/migration.rb:1036:in `migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:238:in `migrate'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/railties/databases.rake:84:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>'
/app/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:28:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:463:in `exec'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:27:in `dispatch'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/cli.rb:18:in `start'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.6.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:104:in `load'
/app/bin/bundle:104:in `<main>'
I've looked around a bit but still cant get it to work. I can see that it has to do with my user_profiles.
My user profiles model:
class UserProfile < ApplicationRecord
belongs_to :user, class_name: 'User', foreign_key: 'user_id'
validates_uniqueness_of :user_id
end
This is my user profile migrate:
class CreateUserProfiles < ActiveRecord::Migration[6.0]
def change
create_table :user_profiles do |t|
t.integer :user_id
t.string :name
t.integer :age
t.string :address
t.string :ptName
t.string :bio
t.timestamps
end
add_foreign_key :user_profiles, :users, column: :user_id
add_index :user_profiles, :user_id, unique: true
end
end
The error is occurring as when i go to view my app through heroku I see this: Application error. So I try and run: heroku run rake db:migrate and the error in the title occurs. I think it might have to do with Pg being more strict with foreign keys. Any suggestions?
From Rails 5 - when we reference a model, index on the foreign_key is automatically created.
Just do it like below -
class CreateUserProfiles < ActiveRecord::Migration[6.0]
def change
create_table :user_profiles do |t|
t.references :user, null: false, foreign_key: true
t.string :name
t.integer :age
t.string :address
t.string :ptName
t.string :bio
t.timestamps
end
end
end

Rails/Heroku Migration Error wrong number of arguments (given 1, expected 0)

I have an error when trying to run heroku run rake db:migrate. What is interesting about this error is that I do not get it locally, nor do I get it on our production server (also on Heroku). Only the staging server is experiencing this issue.
It seems like the timestamps in a particular migration is throwing the error:
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'
...
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'
Here is the migration file /app/db/migrate/20170609154646_create_orders.rb:
class CreateOrders < ActiveRecord::Migration[5.0]
def change
create_table :orders do |t|
t.string :source, null: false
t.integer :source_order_id
t.integer :customer_id, null: false
t.string :type
t.boolean :fulfilled, default: false
t.timestamps :fullfilled_date
t.boolean :arrived, default: false
t.timestamps :arrived_date
t.timestamps :due_date
t.boolean :late, default: false
t.text :requester_notes
t.text :provider_notes
t.float :subtotal, null: false
t.float :total, null: false
t.float :discount
t.references :provider, references: :tailors, index: true
t.references :requester, references: :retailers, index: true
t.timestamps
end
end
end
And the full stack trace:
λ ~: heroku run rake db:migrate -a [app-name] --trace
Running rake db:migrate --trace on ⬢ [app-name]... up, run.2263 (Free)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
D, [2018-01-29T18:44:23.091296 #4] DEBUG -- : (21.4ms) SELECT pg_try_advisory_lock(2914900371259544535)
D, [2018-01-29T18:44:23.203445 #4] DEBUG -- : (16.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
I, [2018-01-29T18:44:23.207416 #4] INFO -- : Migrating to CreateOrders (20170609154646)
D, [2018-01-29T18:44:23.230850 #4] DEBUG -- : (19.2ms) BEGIN
== 20170609154646 CreateOrders: migrating =====================================
-- adapter_name()
-> 0.0000s
-- adapter_name()
-> 0.0000s
-- create_table(:orders, {:id=>:integer})
D, [2018-01-29T18:44:23.246188 #4] DEBUG -- : (9.3ms) ROLLBACK
D, [2018-01-29T18:44:23.256813 #4] DEBUG -- : (9.8ms) SELECT pg_advisory_unlock(2914900371259544535)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:49:in `block in create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:282:in `create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:45:in `create_table'
/app/db/migrate/20170609154646_create_orders.rb:3:in `change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1317:in `with_advisory_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/airbrake-7.1.0/lib/airbrake/rake.rb:19:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:188:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `load'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:360:in `exec'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor.rb:369:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:20:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/base.rb:444:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:10:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:49:in `block in create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:282:in `create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:45:in `create_table'
/app/db/migrate/20170609154646_create_orders.rb:3:in `change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1317:in `with_advisory_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/airbrake-7.1.0/lib/airbrake/rake.rb:19:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:188:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `load'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:360:in `exec'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor.rb:369:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:20:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/base.rb:444:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:10:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => db:migrate
If anyone has any ideas what could be causing this, it would be greatly appreciated!
You should use datetime instead of timestamp for columns 'fullfilled_date', 'arrived_date' and 'due_date' as timestamp will not take any arguments
def change
create_table :orders do |t|
t.string :source, null: false
t.integer :source_order_id
t.integer :customer_id, null: false
t.string :type
t.boolean :fulfilled, default: false
t.datetime :fullfilled_date
t.boolean :arrived, default: false
t.datetime :arrived_date
t.datetime :due_date
t.boolean :late, default: false
t.text :requester_notes
t.text :provider_notes
t.float :subtotal, null: false
t.float :total, null: false
t.float :discount
t.references :provider, references: :tailors, index: true
t.references :requester, references: :retailers, index: true
t.timestamps
end
end

ActiveRecord::PendingMigrationError: Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development

NEWBIE: I am trying to set up the membership part of my site. I ran the following commands:
git checkout development
git merge user_authentication
git checkout -b stripe_integration
bundle exec rails g migration CreatePlans
and received the this error:
ActiveRecord::PendingMigrationError: Migrations are pending. To
resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
I've tried running it and other commands with no success. Below are links to other Stack Overflow answers to this issue that did not work for me and a full trace.
Link from Stack Overflow 1
Link from Stack Overflow 2
Full trace:
kmcrayton7:~/workspace (stripe_integration) $ bin/rake db:migrate RAILS_ENV=development
== 20151209220651 AddDeviseToUsers: migrating =================================
-- change_table(:users)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `block in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:454:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:490:in `block (3 levels) in <class:Table>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:489:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:489:in `block (2 levels) in <class:Table>'
/home/ubuntu/workspace/db/migrate/20151209220651_add_devise_to_users.rb:5:in `block in up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:349:in `change_table'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:649:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:641:in `method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:406:in `method_missing'
/home/ubuntu/workspace/db/migrate/20151209220651_add_devise_to_users.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:558:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:598:in `exec_migration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:578:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:577:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:752:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/transactions.rb:208:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:953:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:807:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:785:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `block in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:454:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:490:in `block (3 levels) in <class:Table>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:489:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:489:in `block (2 levels) in <class:Table>'
/home/ubuntu/workspace/db/migrate/20151209220651_add_devise_to_users.rb:5:in `block in up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:349:in `change_table'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:649:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:641:in `method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:406:in `method_missing'
/home/ubuntu/workspace/db/migrate/20151209220651_add_devise_to_users.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:558:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:598:in `exec_migration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:578:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:577:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:752:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/transactions.rb:208:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:953:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:807:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:785:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
-e:1:in `<main>'
SQLite3::SQLException: duplicate column name: email
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `block in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:454:in `add_column'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:490:in `block (3 levels) in <class:Table>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:489:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_definitions.rb:489:in `block (2 levels) in <class:Table>'
/home/ubuntu/workspace/db/migrate/20151209220651_add_devise_to_users.rb:5:in `block in up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:349:in `change_table'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:649:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `say_with_time'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:641:in `method_missing'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:406:in `method_missing'
/home/ubuntu/workspace/db/migrate/20151209220651_add_devise_to_users.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:558:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:598:in `exec_migration'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:578:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:577:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:752:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/transactions.rb:208:in `transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:953:in `block in migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `each'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:807:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/migration.rb:785:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.1.0/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Which email should I remove from the add_devise_to_user.rb file?
class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
# Uncomment below if timestamps were not included in your original model.
# t.timestamps
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
raise ActiveRecord::IrreversibleMigration
end
end
Looking into the AddDeviseToUsers migration error stack trace, you may notice that you have a duplicate email column. You already have an email column on the users table and that particular migration is trying to add another one.
I'd advise you to edit AddDeviseToUsers to remove the email column creation. If you're not familiar with Rails directory structure, you may find that file at db/migrate/xxxxxxxxxxx_add_devise_to_users.rb
I hope it helps.

RoR db:migrate not working

I am using my local environment on Mac OS X with Rails 4.
When trying to run my migration, it is not running.
I receive the following output:
*******-C02MGBVJFD57:myapp *************$ bundle exec rake db:migrate
Your Gemfile lists the gem faker (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Your Gemfile lists the gem factory_girl_rails (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
== 20140815221246 AddPasswordDigestToUsers: migrating =========================
-- add_column(:users, :password_digest, :string)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Duplicate column name 'password_digest': ALTER TABLE `users` ADD `password_digest` varchar(255)/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/mysql2_adapter.rb:228:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/Users/*************/workspace/myapp/db/migrate/20140815221246_add_password_digest_to_users.rb:3:in `change'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:1040:in `ddl_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
ActiveRecord::StatementInvalid: Mysql2::Error: Duplicate column name 'password_digest': ALTER TABLE `users` ADD `password_digest` varchar(255)
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/mysql2_adapter.rb:228:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/Users/*************/workspace/myapp/db/migrate/20140815221246_add_password_digest_to_users.rb:3:in `change'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:1040:in `ddl_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Mysql2::Error: Duplicate column name 'password_digest'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/mysql2_adapter.rb:228:in `execute'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:375:in `add_column'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/Users/*************/workspace/myapp/db/migrate/20140815221246_add_password_digest_to_users.rb:3:in `change'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:1040:in `ddl_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/*************/.rvm/gems/ruby-2.1.2#myapp/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Any idea what is wrong?
EDIT:
The schema for the users table below:
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
t.string "remember_digest"
end
Users Migration:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password_digest
t.timestamps
end
end
end
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
class AddRememberDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_digest, :string
end
end
The issue is happening because in your CreateUsers migration, you are already creating a users table with the password_digest column as evidenced by this line:
t.string :password_digest
Then, in your AddPasswordDigestToUsers migration, you're trying to add a column with the same name to the users table:
add_column :users, :password_digest, :string
This is where the migration failed with the error Mysql2::Error: Duplicate column name 'password_digest'.
Are you sure you need the AddPasswordDigestToUsers file? It doesn't seem like it because you already added the column in the CreateUsers migration.
I think you can simply delete the AddPasswordDigestToUsers migration file and try re-running bundle exec rake db:migrate.

rake aborted, wrong number of arguments

I'm trying to add a counter_cache to my tag table
when I run my migration to add the column it aborts (but not before adding the column)
I don't understand it, and although it makes the column, it's going stop any future migrations. How do i fix this?
== AddCountToTags: migrating =================================================
-- add_column(:tags, :reports_count, :integer, {:default=>0})
-> 0.1405s
rake aborted!
An error has occurred, all later migrations canceled:
wrong number of arguments (0 for 1)
The trace:
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/counter_cache.rb:17:in `reset_counters'
/Dropbox/Shared/repair/db/migrate/20120120234938_add_count_to_tags.rb:5:in `up'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:314:in `block in migrate'
/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:295:in `measure'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:314:in `migrate'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:397:in `migrate'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:539:in `block (2 levels) in migrate'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:615:in `call'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:615:in `ddl_transaction'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:538:in `block in migrate'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:525:in `each'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:525:in `migrate'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:435:in `up'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/migration.rb:417:in `migrate'
/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/railties/databases.rake:151:in `block (2 levels) in <top (required)>'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
migration file:
class AddCountToTags < ActiveRecord::Migration
def self.up
add_column :tags, :reports_count, :integer, :default => 0
Tag.reset_counters
Tag.find(:all).each do |t|
t.update_attribute(:reports_count, t.reports.length)
end
end
def self.down
remove_column :tags, :reports_count
end
end
relevant models:
class TagAssignment < ActiveRecord::Base
belongs_to :tag, :counter_cache => :reports_count
belongs_to :report
end
class Tag < ActiveRecord::Base
has_many :tag_assignments, :dependent => :destroy
has_many :reports, :through => :tag_assignments
end
From what I see here you need to pass an id to reset_counters.
it seems that what you want to do should be (untested) done by:
Tag.find_each do |t|
Tag.reset_counters(t.id, :reports)
end

Resources