2017-04-14 15 views
1

以下のサーバーでrake db:migrateを実行しようとしました。rake db:migrate実行中のエラー

第一サーバー:

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と信頼できる同じレイクバージョンの別のサーバをセットアップしました。データベースはまだエンジンバージョン5.6.2のAWS Aurora RDSにあり、移行は完了しました。

これが実際の問題であったかどうかはわかりませんが、問題は今解決されました。

ありがとうございます。

2

あなたはインデックスが列名に基づいているので、最初のインデックスを追加> =を削除する必要があります:

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

私は最初のサーバーであるローカルサーバー上で実行しようとし、移行が完了しました。 –

関連する問題