【发布时间】:2014-11-12 19:46:41
【问题描述】:
我们不断遇到acts-as-taggable-on gem 的构建错误,这已被证明非常难以捉摸:
== 20140517050649 ActsAsTaggableOnMigration: migrating ========================
-- create_table(:tags)
-> 0.0057s
-- create_table(:taggings)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateTable: ERROR: relation "taggings" already exists
: CREATE TABLE "taggings" ("id" serial primary key, "tag_id" integer, "taggable_id" integer, "taggable_type" character varying(255), "tagger_id" integer, "tagger_type" character varying(255), "context" character varying(128), "created_at" timestamp) /home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in `create_table'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:649:in `block in method_missing'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `block in say_with_time'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `say_with_time'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:641:in `method_missing'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:406:in `method_missing'
/home/apps/api/releases/20141107204423/db/migrate/20140517050649_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:8:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:558:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:598:in `exec_migration'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:578:in `block in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:577:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:752:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `ddl_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:953:in `block in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `each'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "taggings" already exists
: CREATE TABLE "taggings" ("id" serial primary key, "tag_id" integer, "taggable_id" integer, "taggable_type" character varying(255), "tagger_id" integer, "tagger_type" character varying(255), "context" character varying(128), "created_at" timestamp)
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in `create_table'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:649:in `block in method_missing'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `block in say_with_time'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `say_with_time'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:641:in `method_missing'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:406:in `method_missing'
/home/apps/api/releases/20141107204423/db/migrate/20140517050649_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:8:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:558:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:598:in `exec_migration'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:578:in `block in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:577:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:752:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `ddl_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:953:in `block in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `each'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
PG::DuplicateTable: ERROR: relation "taggings" already exists
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in `create_table'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:649:in `block in method_missing'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `block in say_with_time'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `say_with_time'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:641:in `method_missing'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:406:in `method_missing'
/home/apps/api/releases/20141107204423/db/migrate/20140517050649_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:8:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:558:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:598:in `exec_migration'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:578:in `block in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:577:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:752:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `ddl_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:953:in `block in migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `each'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate'
/home/apps/api/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/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)
deploy@apistaging:/home/apps/api/current$
这个问题迫使我删除表,然后重新运行 rake db:migrate。在我尝试使用 PG 命令备份和恢复数据库之前,这并不是一个巨大的痛苦。那里出现了同样的错误。
有人遇到过这个问题吗?
更新
我应该注意,这只发生在服务器上,而不是本地。
导轨 4.1 红宝石 2.1
【问题讨论】:
-
错误非常简单——您的数据库(出于某种原因)已经有一个“标记”表。您是否在另一个迁移中手动创建标记表?
-
@JTG 不,我已经仔细检查了所有迁移 + 这不会在本地发生。
标签: ruby-on-rails ruby tags