pca*_*asa 7 ruby-on-rails ruby-on-rails-3
使用sqlite3进行本地开发.Prod DB是MySql.
有一个用于列更改的迁移文件.
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
Run Code Online (Sandbox Code Playgroud)
错误说出来 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
Run Code Online (Sandbox Code Playgroud)
就我个人而言,我希望我的生产和开发环境尽可能匹配。它有助于避免陷阱。如果我要部署 MySQL,我也会使用 MySQL 来运行我的开发环境。此外,我对 SQLite 也不是很熟悉,所以这种方法吸引了我懒惰的一面 - 我只需要知道一个数据库的来龙去脉。