2011-04-06 78 views
7

使用本地開發的sqlite3。 Prod DB是MySql。Rails遷移和列更改

有一個列更改的遷移文件。

class ChangeDateToOrders < ActiveRecord::Migration 
    def self.up 
    change_column(:orders, :closed_date, :datetime) 
    end 

    def self.down 
    change_column(:orders, :closed_date, :date) 
    end 
end 

錯誤出來說index name 'temp_index_altered_orders_on_closed_location_id_and_parent_company_id' on table 'altered_orders' is too long; the limit is 64 characters

知道有關於使用SQLite索引名的限制,但有一種解決方法嗎?

編輯 我使用的解決方法。

class ChangeDateToOrders < ActiveRecord::Migration 
    def self.up 
    remove_index(:orders, [:closed_location_id, :parent_company_id]) 
    change_column(:orders, :closed_date, :datetime) 
    add_index(:orders, [:closed_location_id, :parent_company_id], :name => "add_index_to_orders_cli_pci") 
    end 

    def self.down 
    remove_index(:orders, :name => "add_index_to_orders_cli_pci") 
    change_column(:orders, :closed_date, :date) 
    add_index(:orders, [:closed_location_id, :parent_company_id]) 
    end 
end 

回答

1

就我個人而言,我喜歡我的生產和開發環境儘可能匹配。它有助於避免陷阱。如果我正在部署MySQL,我也會使用MySQL運行我的開發環境。此外,我對SQLite也不是很熟悉,所以這種方法吸引了我懶惰的一面 - 我只需要知道一個db的來龍去脈。

0

你可以破解你的活動記錄副本;添加以下

  opts[:name] = opts[:name][0..63] # can't be more than 64 chars long 

圍繞線535(在3.2.9版本)$ GEM_HOME /寶石/ ActiveRecord的-3.2.9/lib目錄/ active_record/connection_adapters/sqlite_adapter.rb

這是一個黑客,但它的可能會讓你經歷一個障礙。如果我有更多時間,我會着手編寫測試並向Rails核心團隊發送一個pull請求。