2017-04-14 139 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

我已经尝试在本地服务器上运行它,这是第一台服务器,迁移完成。 –