我曾尝试在下面提到的服务器上运行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
我已经在成功完成的第一台服务器上运行了迁移但是当我尝试使用以下命令运行rake DB migrate而不是获取错误时。
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
有什么想法吗?
答案 0 :(得分:2)
你需要删除=&gt;首先添加索引,因为索引基于列名:
remove_index :locations, :street_or_locality
rename_column :locations, :street_or_locality, :street
add_index :locations, :street
答案 1 :(得分:1)
只是更新。
我已经设置了另一台服务器,其中ubuntu 14.04可信赖且相同的rake版本。该数据库仍在AWS Aurora RDS上,引擎版本为5.6.2,现在已完成迁移。
我不确定这是否是实际问题,但现在问题已得到解决。
谢谢。