2017-04-14 134 views
1

我試圖在下面提到的服務器上運行rake db:migrate。運行rake db時出錯:遷移

1日服務器:

OS: Ubuntu 14.04 Trusty 
Mysql Version: 5.6.33 
Rake Version: 12.0.0 

第二個服務器:

OS: Ubuntu 16.04 Xeniel 
Mysql Version: 5.6.2 
Rake Version: 10.4.2 

我已經運行已成功完成第一臺服務器上遷移,但是當我試圖運行耙DB與遷移下面的命令比獲取錯誤。

RAILS_ENV="deve" bundle exec rake db:migrate 

錯誤代碼:

== 20150714111224 RenameColumnStreetOrLocalityToStreetLocations: migrating ==== 
-- rename_column(:locations, :street_or_locality, :street) 
rake aborted! 
StandardError: An error has occurred, all later migrations canceled: 

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INDEX `index_locations_on_street_or_locality` TO `index_locations_on_street`' at line 1: ALTER TABLE `locations` RENAME INDEX `index_locations_on_street_or_locality` TO `index_locations_on_street` 
/home/ubuntu/code/platform/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `_query' 
/home/ubuntu/code/platform/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `block in query' 
/home/ubuntu/code/platform/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `handle_interrupt' 
/home/ubuntu/code/platform/shared/bundle/ruby/2.2.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `query' 
/home/ubuntu/code/platform/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:299:in `block in execute' 

請在下面找到遷移代碼。

class RenameColumnStreetOrLocalityToStreetLocations < ActiveRecord::Migration 
    def change 
    rename_column :locations,:street_or_locality,:street 
    end 
end 

任何想法?

+1

您需要發佈您的遷移代碼。 – lcguida

+0

@MohitKumar請更新問題的代碼 – Iceman

+1

謝謝你的迴應。我已經更新了問題中的代碼。 –

回答

1

只是一個更新。

我已經建立了與Ubuntu 14.04可靠和相同的耙子版本的另一臺服務器。該數據庫仍然位於AWS Aurora RDS Engine 5.6.2版上,現在遷移已完成。

我不確定這是否是實際問題,但現在問題已解決。

謝謝。

2

你需要以來,該指數是基於列的名稱以去除=>第一添加索引:

remove_index :locations, :street_or_locality 
rename_column :locations, :street_or_locality, :street 
add_index :locations, :street 
+0

我已經嘗試在本地服務器上運行它,這是第一臺服務器,遷移完成。 –