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

RubyonRails:PostgreSQL/Capistrano在部署时覆盖迁移

  •  0
  • Salman  · 技术社区  · 7 年前

    我已经更新了rails,spree(电子商务框架),并添加了一些新的gems。这些都需要在更新和安装之后迁移。在开发应用程序上,我遇到了一个问题。每当我试图迁移时,都会出错

    问题

    activeRecord::statementInvalid:pg::DuplicateTable:error:relation“index_products_promotion_rules_on_product_id”已存在 :在“spree-products-promotion-rules”上创建索引“index-products-promotion-rules-on-product-id”(“product-id”)。

    当我尝试将我的网站部署到实时服务器时,错误/问题将返回,

    我已经尝试从 migration file schema.rb

    是否保存以从

    还是有其他方法来解决这个问题?

      create_table "spree_product_promotion_rules", force: :cascade do |t|
        t.integer "product_id"
        t.integer "promotion_rule_id"
        t.index ["product_id"], name: "index_products_promotion_rules_on_product_id"
        t.index ["promotion_rule_id", "product_id"], name: "index_products_promotion_rules_on_promotion_rule_and_product"
    

    迁移文件

    # This migration comes from spree (originally 20120831092359)
    class SpreePromoOneTwo < ActiveRecord::Migration[4.2]
      def up
    
        # This migration is just a compressed migration for all previous versions of spree_promo
        return if table_exists?(:spree_products_promotion_rules)
    
        create_table :spree_products_promotion_rules, :id => false, :force => true do |t|
          t.references :product
          t.references :promotion_rule
        end
    
        add_index :spree_products_promotion_rules, [:product_id], :name => 'index_products_promotion_rules_on_product_id'
        add_index :spree_products_promotion_rules, [:promotion_rule_id], :name => 'index_products_promotion_rules_on_promotion_rule_id'
    
        create_table :spree_promotion_actions, force: true do |t|
          t.references :activator
          t.integer    :position
          t.string     :type
        end
    
        create_table :spree_promotion_rules, force: true do |t|
          t.references :activator
          t.references :user
          t.references :product_group
          t.string     :type
          t.timestamps null: false
        end
    
        add_index :spree_promotion_rules, [:product_group_id], name: 'index_promotion_rules_on_product_group_id'
        add_index :spree_promotion_rules, [:user_id], name: 'index_promotion_rules_on_user_id'
    
        create_table :spree_promotion_rules_users, id: false, force: true do |t|
          t.references :user
          t.references :promotion_rule
        end
    
        add_index :spree_promotion_rules_users, [:promotion_rule_id], name: 'index_promotion_rules_users_on_promotion_rule_id'
        add_index :spree_promotion_rules_users, [:user_id], name: 'index_promotion_rules_users_on_user_id'
      end
    end
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Salman    7 年前

    最终我下载了数据库,所以我可以尝试在本地迁移。我更改了文件,删除了已经存在的行并执行rails db:migrate,直到不再收到错误消息。

    推荐文章