代码之家  ›  专栏  ›  技术社区  ›  martin

部署时迁移数据库更改时Capistrano失败

  •  0
  • martin  · 技术社区  · 9 年前

    我的开发设置没有解决下面描述的任何问题。

    我使用capistrano部署到生产环境中,当我有新的数据库迁移时,我在部署时遇到以下错误-这些迁移在开发中已经成功。 我已将DB文件夹链接到我的deploy.rb中的共享文件夹

    有什么想法吗??

    DEBUG [a75e33cf]    Tasks: TOP => db:migrate
    (See full trace by running task with --trace)
    (Backtrace restricted to imported tasks)
    cap aborted!
    SSHKit::Runner::ExecuteError: Exception while executing on host 192.168.2.103: Exception while executing on host 192.168.2.103: rake exit status: 1
    rake stdout: == 20160204094713 AddColumnToCatalog: migrating ===============================
    -- remove_index("instances", ["catalog_id"], {:name=>"index_instances_on_catalog_id"})
    rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:
    
    wrong number of arguments (3 for 1..2)/home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:578:in `remove_index'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in `block in method_missing'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `block in say_with_time'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `say_with_time'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in `method_missing'
    /home/deploy/apps/phototank/releases/20160206231645/db/migrate/20160204094713_add_column_to_catalog.rb:3:in `change'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:608:in `exec_migration'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in `block in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `block in ddl_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in `transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `ddl_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in `execute_migration_in_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in `block in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `each'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in `up'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
    ArgumentError: wrong number of arguments (3 for 1..2)
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:578:in `remove_index'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in `block in method_missing'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `block in say_with_time'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `say_with_time'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in `method_missing'
    /home/deploy/apps/phototank/releases/20160206231645/db/migrate/20160204094713_add_column_to_catalog.rb:3:in `change'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:608:in `exec_migration'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in `block in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `block in ddl_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in `transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `ddl_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in `execute_migration_in_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in `block in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `each'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in `up'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
    Tasks: TOP => db:migrate
    (See full trace by running task with --trace)
    rake stderr: Nothing written
    
    SSHKit::Runner::ExecuteError: Exception while executing on host 192.168.2.103: rake exit status: 1
    rake stdout: == 20160204094713 AddColumnToCatalog: migrating ===============================
    -- remove_index("instances", ["catalog_id"], {:name=>"index_instances_on_catalog_id"})
    rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:
    
    wrong number of arguments (3 for 1..2)/home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:578:in `remove_index'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in `block in method_missing'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `block in say_with_time'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `say_with_time'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in `method_missing'
    /home/deploy/apps/phototank/releases/20160206231645/db/migrate/20160204094713_add_column_to_catalog.rb:3:in `change'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:608:in `exec_migration'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in `block in migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in `migrate'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in `block in ddl_transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
    /home/deploy/apps/phototank/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   will_in_wi Md Sirajus Salayhin    9 年前

    迁移中的语法错误。这个 remove_index 方法采用一个标准参数和命名参数。有问题的迁移有两个标准参数和一个命名参数。

    http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/remove_index

    remove_index("instances", ["catalog_id"], {:name=>"index_instances_on_catalog_id"})
    

    应该是

    remove_index("instances", column: 'catalog_id', name: 'index_instances_on_catalog_id')
    

    这是未经测试的代码,请提前验证。您可能可以获取生产数据库的副本并运行 rake db:migrate 本地进行测试和调试。