SQLite3::SQLException: in migration - ruby-on-rails

Migration:
class AddUserIdToPhotos < ActiveRecord::Migration
def self.up
add_column :photos, :user_id, :integer
execute 'update photos inner join albums on albums.id = photos.album_id set photos.user_id = albums.user_id'
end
def self.down
remove_column :photos, :user_id
end
end
rake db:migrate, display error:
-- add_column(:photos, :user_id, :integer) -> 0.0010s
-- execute("update photos inner join albums on albums.id = photos.album_id set photos.user_id = albums.user_id") rake aborted!
StandardError: An error has occurred, this and all later migrations
canceled:
SQLite3::SQLException: near "inner": syntax error: update photos inner
join albums on albums.id = photos.album_id set photos.user_id =
albums.user_id/home/borowskiy/projects/galaxy/bdsmgalaxy/db/migrate/20110731191428_add_user_id_to_photos.rb:4:in
`up'
with trace:
SQLite3::SQLException: near "inner": syntax error: update photos inner join albums on albums.id = photos.album_id set photos.user_id = albums.user_id/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in `block in execute'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-3.2.22/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-mini-profiler-0.9.7/lib/patches/db/activerecord.rb:17:in `log_with_miniprofiler'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in `execute'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:466:in `block in method_missing'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:438:in `block in say_with_time'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/benchmark.rb:281:in `measure'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:438:in `say_with_time'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:458:in `method_missing'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:334:in `method_missing'
/home/borowskiy/projects/galaxy/bdsmgalaxy/db/migrate/20110731191428_add_user_id_to_photos.rb:4:in `up'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:370:in `up'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/benchmark.rb:281:in `measure'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:410:in `block in migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:389:in `migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:528:in `migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:775:in `call'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:775:in `block in ddl_transaction'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/transactions.rb:208:in `transaction'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:775:in `ddl_transaction'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:719:in `block in migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:700:in `each'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:700:in `migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:570:in `up'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:551:in `migrate'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/home/borowskiy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/home/borowskiy/.rbenv/versions/2.0.0-p247/bin/rake:23:in `load'
/home/borowskiy/.rbenv/versions/2.0.0-p247/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate

You SQL query is wrong. The correct sql update query should be like this
update photos set photos.user_id = albums.user_id from albums where albums.id = photos.album_id
Please change your migration file to this
class AddUserIdToPhotos < ActiveRecord::Migration
def self.up
add_column :photos, :user_id, :integer
execute "update photos set photos.user_id = albums.user_id from albums where albums.id = photos.album_id"
end
def self.down
remove_column :photos, :user_id
end
end
and run it again.

Related

PG::UndefinedTable: ERROR: relation "step_images" does not exist

On migration I get the following error message:
PG::UndefinedTable: ERROR: relation "step_images" does not exist LINE 5: WHERE a.attrelid = '"step_images"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"step_images"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
in db
class CreateStepImages < ActiveRecord::Migration
def change
create_table :step_images do |t|
t.string :text
t.attachment :image1
t.attachment :image2
t.attachment :image3
t.attachment :image4
t.attachment :image5
t.references :steptation, index: true
t.timestamps
end
end
end
in step_image model
class StepImage < ActiveRecord::Base
belongs_to :steptation
belongs_to :user
end
in steptation model
has_many :step_images
in step_images controller
class StepImagesController < ApplicationController
before_action :find_step_image ,only:[:show,:update,:edit,:destroy]
before_action :set_steptation, only: [:new, :create]
def new
#steptation =Steptation.find(params[:id])
#step_image = #steptation.step_images.build
#user = current_user
end
def index
end
def create
#step_image = Step_image.new(step_image_params)
#step_image.user_id = current_user.id
if #step_image.save
#steptation.step_images << #step_image
redirect_to case_path(id: #steptation.case_id)
else
render :new
end
end
def edit
end
def update
if #step_image.update(step_image_params)
redirect_to root_path, alert: "steptation Information updated successfully"
else
flash.now[:error] = "Couldn't update!"
render :edit
end
end
def destroy
#step_image.destroy
redirect_to root_path, notice: "step_image deleted Successfully"
end
private
def set_steptation
#steptation = Steptation.find(params[:id])
end
def find_step_image
#step_image = Step_image.find(params[:id])
end
def step_image_params
params.require(:step_image).permit(:text,:image1,:image2,:image3,:image4,:image5)
end
end
I did rake db:rollback STEP=1
$ rake db:rollback STEP=1
ActiveRecord::SchemaMigration Load (0.9ms) SELECT "schema_migrations".* FROM "schema_migrations"
ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to CreateStepImages (20201119214001)
(0.1ms) BEGIN
== 20201119214001 CreateStepImages: reverting =================================
-- drop_table(:step_images)
(10.3ms) DROP TABLE "step_images"
(0.2ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: table "step_images" does not exist
: DROP TABLE "step_images"
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activesupport-4.2.11.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:127:in `drop_table'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:665:in `block in method_missing'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:634:in `block in say_with_time'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:634:in `say_with_time'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:654:in `method_missing'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:499:in `block in revert'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:498:in `each'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:498:in `revert'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:606:in `exec_migration'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:591:in `block in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:590:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:768:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1023:in `block in execute_migration_in_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1069:in `block in ddl_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/transactions.rb:220:in `transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1069:in `ddl_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1022:in `execute_migration_in_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:984:in `block in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:980:in `each'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:980:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:830:in `down'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:935:in `move'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:812:in `rollback'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/railties/databases.rake:118:in `block (2 levels) in <top (required)>'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/Users/nour/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in `eval'
/Users/nour/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: table "step_images" does not exist
: DROP TABLE "step_images"
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activesupport-4.2.11.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:127:in `drop_table'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:665:in `block in method_missing'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:634:in `block in say_with_time'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:634:in `say_with_time'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:654:in `method_missing'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:499:in `block in revert'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:498:in `each'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:498:in `revert'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:606:in `exec_migration'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:591:in `block in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:590:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:768:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1023:in `block in execute_migration_in_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1069:in `block in ddl_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/transactions.rb:220:in `transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1069:in `ddl_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1022:in `execute_migration_in_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:984:in `block in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:980:in `each'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:980:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:830:in `down'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:935:in `move'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:812:in `rollback'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/railties/databases.rake:118:in `block (2 levels) in <top (required)>'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/Users/nour/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in `eval'
/Users/nour/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in `<main>'
Caused by:
PG::UndefinedTable: ERROR: table "step_images" does not exist
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:127:in `drop_table'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:665:in `block in method_missing'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:634:in `block in say_with_time'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:634:in `say_with_time'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:654:in `method_missing'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:499:in `block in revert'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:498:in `each'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:498:in `revert'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:606:in `exec_migration'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:591:in `block in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:590:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:768:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1023:in `block in execute_migration_in_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1069:in `block in ddl_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/transactions.rb:220:in `transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1069:in `ddl_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:1022:in `execute_migration_in_transaction'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:984:in `block in migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:980:in `each'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:980:in `migrate'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:830:in `down'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:935:in `move'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:812:in `rollback'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/activerecord-4.2.11.1/lib/active_record/railties/databases.rake:118:in `block (2 levels) in <top (required)>'
/Users/nour/.rvm/gems/ruby-2.5.5/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/Users/nour/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in `eval'
/Users/nour/.rvm/gems/ruby-2.5.5/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:rollback
(See full trace by running task with --trace)
When running rake db:migrate, rails will load the full application code before executing the migrations. Therefore, when you have already defined the StepImage class, rails will try to find the corresponding table. However, at this point in time, the table has not yet been created, which then causes this error. Try to comment out the StepImage class and everything associated with it (e.g. by moving the files out of the project folder) and re-run the migration. If it works, move the files back.
It seems like the rollback failed for the same reason: the step_images table has never been created. In such cases, I typically do the following:
Put the migration content into begin/rescue/end:
def change
begin
create_table :step_images do |t|
t.string :text
t.attachment :image1
#...
end
rescue
end
end
Rollback this migration to get to the original state. The rescue block will catch the error and the migration should succeed.
Use psql to check that the step_images table is actually gone. If not, delete it with psql.
Sanitize the source code: remove everything that has to do with the new step_images table. Start with this migration. Move it out of the project, so that rails c will not complain about a pending migration. Then move all models, controller, etc. out of the project. Remove all associations pointing to the new model (comment out). Otherwise, relations pointing to non-existing models/tables will cause more errors.
Sanitize until rails c succeeds in starting the application.
Move the migration back into db/migrations and run it.
If this succeeds, bring everything back in again. If unsure, do in multiple small steps and check in-between by running rails c.
Hope this helps!

Rails Money migration fails

I am trying to import all migrations. However, the use of t.monetize :total, currency: { present: false } within a create_table block seems to crash with the following error message:
class AddAddressAndOrder < ActiveRecord::Migration[5.1]
def change
create_table :line_items do |t|
t.belongs_to :order
t.integer :quantity, default: 0
t.monetize :price, currency: { present: false }
t.monetize :total, currency: { present: false }
t.timestamps
end
end
end
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2..3)
Each time I get to a t.monetize (or t.money) column reference I receive the same error... added below (including --trace):
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== 20160901101357 AddAddressAndOrder: migrating ===============================
-- create_table(:orders)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
wrong number of arguments (given 1, expected 2..3)
schema_definitions.rb:311:in `column'
table_pg_rails4.rb:9:in `block in monetize'
table_pg_rails4.rb:6:in `each'
table_pg_rails4.rb:6:in `monetize'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:20:in `block in change'
schema_statements.rb:282:in `create_table'
abstract_mysql_adapter.rb:363:in `create_table'
method_missing'
say_with_time'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
`method_missing'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:18:in `change'
`exec_migration'
migrate'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
migrate'
connection_pool.rb:408:in `with_connection'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
execute_migration_in_transaction'
`ddl_transaction'
`execute_migration_in_transaction'
migrate_without_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
`migrate_without_lock'
migrate'
`with_advisory_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
`migrate'
levels) in <top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
`invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
top_level'
`run_with_threads'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
`standard_exception_handling'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/Users/Paul/.rvm/gems/ruby-2.5.0#global/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `load'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `<main>'
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 2..3)
schema_definitions.rb:311:in `column'
table_pg_rails4.rb:9:in `block in monetize'
table_pg_rails4.rb:6:in `each'
table_pg_rails4.rb:6:in `monetize'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:20:in `block in change'
schema_statements.rb:282:in `create_table'
abstract_mysql_adapter.rb:363:in `create_table'
method_missing'
say_with_time'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
`method_missing'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:18:in `change'
`exec_migration'
migrate'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
migrate'
connection_pool.rb:408:in `with_connection'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
execute_migration_in_transaction'
`ddl_transaction'
`execute_migration_in_transaction'
migrate_without_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
`migrate_without_lock'
migrate'
`with_advisory_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/Paul/.rvm/gems/ruby-2.5.0#project/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
`migrate'
levels) in <top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
`invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
top_level'
`run_with_threads'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
`standard_exception_handling'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/Users/Paul/.rvm/gems/ruby-2.5.0#global/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `load'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate
My Gemfile.lock looks like this regarding Money-Rails:
money (~> 6.10.1)
money-rails (1.10.0)
activesupport (>= 3.0)
monetize (~> 1.7.0)
money (~> 6.10.0)
railties (>= 3.0)
The docs (https://github.com/RubyMoney/money-rails#migration-helpers) state that this should be fine. So I've no idea what to do.
The issue seems to be within the MoneyRails::ActiveRecord::Migration::Table.monetize method:
module MoneyRails
module ActiveRecord
module MigrationExtensions
module Table
def monetize(accessor, options={})
[:amount, :currency].each do |attribute|
column_present, _, *opts = OptionsExtractor.extract attribute, :no_table, accessor, options
column(*opts) if column_present
end
end
# Removed for brevity
end
end
end
end
No matter what is passed to monetize, it always seems to throw the same error. I really am lost as to what I am doing wrong, so any help would be greatly appreciated.
Are you doing anything in an initializer that might affect the MoneyRails::Configuration#amount_column? Looks like the OptionsExtractor is missing a few things.

Can't migrate psql database after scaffold - Cloud9

I am getting an "wrong number of arguments (given 1, expected 0)" error when trying to run rake db:migrate on my psql database. This asker had the same trouble, but locking my Gemfile "to gem 'arel', '6.0.0.beta2'" and using rails version 4.2.0.beta4 hasn't fixed the issue though I am able to bundle and am absolutely using these versions. Any help would be much appreciated!
Here is the full trace
rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== 20161104230329 Createmytable: migrating ==================================
-- create_table(:mytable)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (given 1, expected 0)
/home/ubuntu/workspace/mydb_api/db/migrate/20161104230329_create_mytable.rb:4:in `block in change'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/schema_statements.rb:199:in `create_table'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:655:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:625:in `block in say_with_time'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:625:in `say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:645:in `method_missing'
/home/ubuntu/workspace/mydb_api/db/migrate/20161104230329_create_mytable.rb:3:in `change'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:599:in `exec_migration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:583:in `block (2 levels) in migrate'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:582:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/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.0.beta4/lib/active_record/migration.rb:581:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:758:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:984:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/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.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:983:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:945:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:813:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:791:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:173:in `invoke'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:152:in `invoke_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:102:in `top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:80:in `block in run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `<main>'
ArgumentError: wrong number of arguments (given 1, expected 0)
/home/ubuntu/workspace/mydb_api/db/migrate/20161104230329_create_mytable.rb:4:in `block in change'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/schema_statements.rb:199:in `create_table'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:655:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:625:in `block in say_with_time'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:625:in `say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:645:in `method_missing'
/home/ubuntu/workspace/mydb_api/db/migrate/20161104230329_create_mytable.rb:3:in `change'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:599:in `exec_migration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:583:in `block (2 levels) in migrate'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:582:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/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.0.beta4/lib/active_record/migration.rb:581:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:758:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:984:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/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.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:983:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:945:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:813:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:791:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.0.beta4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:248:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:243:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/task.rb:173:in `invoke'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:152:in `invoke_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:108:in `block in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:102:in `top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:80:in `block in run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate
Here is the file 20161104230329_create_mytable.rb
class CreateTables < ActiveRecord::Migration
def change
create_table :mytable do |t|
t.name :string
t.param1 :integer
t.param2 :integer
t.param3 :integer
t.timestamps null: false
end
end
end
You have the order of the field/field type options of your migration reversed. Should be
class CreateTables < ActiveRecord::Migration
def change
create_table :mytable do |t|
t.string :name
t.integer :param1
t.timestamps
end
end
end

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