Mastodon: PG::ForeignKeyViolation: ERROR: insert or update on table "statuses" violates foreign key constraint "fk_rails_94a6f70399"

Created on 10 Jun 2017  ·  13Comments  ·  Source: tootsuite/mastodon

I'm a little hesitate to submit the issue because I'm not expert of server side engineer but let me try.
When I updated the latest master code of mastodon on my instance, then I did migrate by

RAILS_ENV=production bundle exec rails db:migrate

I got
PG::ForeignKeyViolation: ERROR: insert or update on table "statuses" violates foreign key constraint "fk_rails_94a6f70399"

Then my migration failed.

I wonder if there is something wrong in migrate file or somehow my DB may be corrupted. Do you have any idea how to fix this issue?

I also put a whole log below,

rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::ForeignKeyViolation: ERROR: insert or update on table "statuses" violates foreign key constraint "fk_rails_94a6f70399"
DETAIL: Key (in_reply_to_id)=(5949) is not present in table "statuses".
: ALTER TABLE "statuses" ADD CONSTRAINT "fk_rails_94a6f70399"
FOREIGN KEY ("in_reply_to_id")
REFERENCES "statuses" ("id")
ON DELETE SET NULL
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in async_exec' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:inblock (2 levels) in execute'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies/interlock.rb:46:in block in permit_concurrent_loads' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/concurrency/share_lock.rb:185:inyield_shares'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies/interlock.rb:45:in permit_concurrent_loads' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:96:inblock in execute'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:612:in block (2 levels) in log' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:611:inblock in log'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/notifications/instrumenter.rb:21:in instrument' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:603:inlog'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:95:in execute' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:930:inadd_foreign_key'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:849:in block in method_missing' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:818:inblock in say_with_time'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:818:in say_with_time' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:838:inmethod_missing'
/home/mastodon/live/db/migrate/20170604144747_add_foreign_keys_for_accounts.rb:5:in change' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:792:inexec_migration'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:776:in block (2 levels) in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:775:inblock in migrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in with_connection' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:774:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:953:in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1230:inblock in execute_migration_in_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1298:in block in ddl_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:225:inblock in transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/transaction.rb:194:in block in within_new_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/transaction.rb:191:inwithin_new_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:225:in transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/transactions.rb:210:intransaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1298:in ddl_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1229:inexecute_migration_in_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1201:in block in migrate_without_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1200:ineach'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1200:in migrate_without_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1148:inblock in migrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1317:in with_advisory_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1148:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1007:in up' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:985:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:171:in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/railties/databases.rake:58:inblock (2 levels) in /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:21:in block in perform' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:18:inperform'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/command.rb:46:in invoke' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands.rb:16:in /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in require' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:inrequire'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in block in require' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:258:inload_dependency'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in require' bin/rails:4:in

'
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "statuses" violates foreign key constraint "fk_rails_94a6f70399"
DETAIL: Key (in_reply_to_id)=(5949) is not present in table "statuses".
: ALTER TABLE "statuses" ADD CONSTRAINT "fk_rails_94a6f70399"
FOREIGN KEY ("in_reply_to_id")
REFERENCES "statuses" ("id")
ON DELETE SET NULL
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in async_exec' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:inblock (2 levels) in execute'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies/interlock.rb:46:in block in permit_concurrent_loads' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/concurrency/share_lock.rb:185:inyield_shares'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies/interlock.rb:45:in permit_concurrent_loads' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:96:inblock in execute'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:612:in block (2 levels) in log' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:611:inblock in log'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/notifications/instrumenter.rb:21:in instrument' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:603:inlog'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:95:in execute' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:930:inadd_foreign_key'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:849:in block in method_missing' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:818:inblock in say_with_time'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:818:in say_with_time' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:838:inmethod_missing'
/home/mastodon/live/db/migrate/20170604144747_add_foreign_keys_for_accounts.rb:5:in change' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:792:inexec_migration'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:776:in block (2 levels) in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:775:inblock in migrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in with_connection' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:774:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:953:in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1230:inblock in execute_migration_in_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1298:in block in ddl_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:225:inblock in transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/transaction.rb:194:in block in within_new_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/transaction.rb:191:inwithin_new_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:225:in transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/transactions.rb:210:intransaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1298:in ddl_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1229:inexecute_migration_in_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1201:in block in migrate_without_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1200:ineach'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1200:in migrate_without_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1148:inblock in migrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1317:in with_advisory_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1148:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1007:in up' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:985:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:171:in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/railties/databases.rake:58:inblock (2 levels) in /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:21:in block in perform' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:18:inperform'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/command.rb:46:in invoke' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands.rb:16:in /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in require' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:inrequire'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in block in require' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:258:inload_dependency'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in require' bin/rails:4:in
'
PG::ForeignKeyViolation: ERROR: insert or update on table "statuses" violates foreign key constraint "fk_rails_94a6f70399"
DETAIL: Key (in_reply_to_id)=(5949) is not present in table "statuses".
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in async_exec' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:inblock (2 levels) in execute'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies/interlock.rb:46:in block in permit_concurrent_loads' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/concurrency/share_lock.rb:185:inyield_shares'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies/interlock.rb:45:in permit_concurrent_loads' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:96:inblock in execute'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:612:in block (2 levels) in log' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:611:inblock in log'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/notifications/instrumenter.rb:21:in instrument' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:603:inlog'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:95:in execute' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:930:inadd_foreign_key'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:849:in block in method_missing' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:818:inblock in say_with_time'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:818:in say_with_time' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:838:inmethod_missing'
/home/mastodon/live/db/migrate/20170604144747_add_foreign_keys_for_accounts.rb:5:in change' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:792:inexec_migration'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:776:in block (2 levels) in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:775:inblock in migrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in with_connection' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:774:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:953:in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1230:inblock in execute_migration_in_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1298:in block in ddl_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:225:inblock in transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/transaction.rb:194:in block in within_new_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/transaction.rb:191:inwithin_new_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:225:in transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/transactions.rb:210:intransaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1298:in ddl_transaction' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1229:inexecute_migration_in_transaction'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1201:in block in migrate_without_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1200:ineach'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1200:in migrate_without_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1148:inblock in migrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1317:in with_advisory_lock' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1148:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:1007:in up' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/migration.rb:985:inmigrate'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/tasks/database_tasks.rb:171:in migrate' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.1/lib/active_record/railties/databases.rake:58:inblock (2 levels) in /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:21:in block in perform' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands/rake/rake_command.rb:18:inperform'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/command.rb:46:in invoke' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/railties-5.1.1/lib/rails/commands.rb:16:in /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in require' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:inrequire'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in block in require' /home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:258:inload_dependency'
/home/mastodon/live/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in require' bin/rails:4:in
'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Migrating to AddForeignKeysForAccounts (20170604144747)
== 20170604144747 AddForeignKeysForAccounts: migrating ========================
-- add_foreign_key(:statuses, :accounts, {:on_delete=>:cascade})
-> 0.1190s
-- add_foreign_key(:statuses, :accounts, {:column=>:in_reply_to_account_id, :on_delete=>:nullify})
-> 0.0562s
-- add_foreign_key(:statuses, :statuses, {:column=>:in_reply_to_id, :on_delete=>:nullify})


  • [x] I searched or browsed the repo’s other issues to ensure this is not a duplicate.
  • [ ] This bug happens on a tagged release and not on master (If you're a user, don't worry about this).

Most helpful comment

Stop Mastodon, run rake mastodon:maintenance:prepare_for_foreign_keys, and then re-run the migrations.

All 13 comments

Stop Mastodon, run rake mastodon:maintenance:prepare_for_foreign_keys, and then re-run the migrations.

OMG, thank you for your advice, wonderfall.
It was perfect to me to fix my issue.

I think we should reopen this, because this is a documentation problem to solve.

There is a known migration process to follow, but it should be documented somewhere.

This should not be reopened, there are release notes for this: https://github.com/tootsuite/mastodon/releases/tag/v1.4.2

In such case, all is fine, indeed.

Might not hurt to reference this in the 1.5.0 notes too, even if short or as a link. I just ran into this and it took me for quite a fun loop through the internet and back, to find it mentioned in the 1.4.2 notes...

I agree. I've already spent over 12h+ fixing my own instance.

I added a note about this to the 1.5.0 release notes.

On one hand, this is a particularly special case, since it was a pretty wide-reaching change. So it can probably be argued that this should be included just on it's own merits. On the other hand, I think we can try and make a habit of adding upgrade notes from the previous minor version to the minor version increment release notes (so 1.4.x changes to 1.5.0, for example). I think trying to go further back then that is difficult and very verbose. I think the trade off of having to read each minor version release notes rather then every release notes is a good middle point to strike the balance.

As someone currently upgrading from 1.2 to 2.x it was helpful to find this issue. As this project evolves there are going to be more and more people who are not on the happy path, and making it as easy as possible to find stuff like this (which totally is relevant to me, but which I was never going to find without going through each release one at a time, or googling the error when it failed) is probably a good idea. :)

Well crap. I just ran sudo docker-compose run --rm web rake mastodon:maintenance:prepare_for_foreign_keys and that worked, but when I tried to run the migrations again I got the following:

```-- remove_column(:statuses, :account_id)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

PG::DependentObjectsStillExist: ERROR: cannot drop table statuses column account_id because other objects depend on it
DETAIL: view public_toots depends on table statuses column account_id
HINT: Use DROP ... CASCADE to drop the dependent objects too.
: ALTER TABLE "statuses" DROP "account_id"
...etc```

Oh jeez, ok, I think I figured it out. I have a view in Postgres called public_toots which I use for my ambassador bot. Turns out that view breaks migrations. Yippee for tech. :)

hi ,
am getting rows count mismatch form oracle to postgres .pls give me any solution for this
ORACLEDB:AGL_EMAILS:971623
POSTGRES:agl_emails:971513

@BR143 we don't have anything related to oracle and nothing in our system is called agl_emails.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cwebber picture cwebber  ·  3Comments

cumbiame picture cumbiame  ·  3Comments

marrus-sh picture marrus-sh  ·  3Comments

KellerFuchs picture KellerFuchs  ·  3Comments

thomaskuntzz picture thomaskuntzz  ·  3Comments