简体   繁体   English

运行rake db:migrate时出错

[英]Error While Running rake db:migrate

I have tried to run rake db:migrate on below-mentioned servers. 我曾尝试在下面提到的服务器上运行rake db:migrate。

1st Server: 第一服务器:

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

2nd Server: 第二服务器:

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

I have run the migration on the first server it was completed successfully but when I am trying to run the rake DB migrate with the following command than getting the error. 我已经在成功完成的第一台服务器上运行了迁移,但是当我尝试使用以下命令运行rake DB migrate而不是获取错误时。

RAILS_ENV="deve" bundle exec rake db:migrate

Error Code: 错误代码:

== 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'

Please find migration code below. 请在下面找到迁移代码。

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

Any idea? 任何想法?

you'll need to remove => add indexes first since the index is based on the column name: 你需要删除=>首先添加索引,因为索引是基于列名:

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

Just an update. 只是一个更新。

I have set up another server with ubuntu 14.04 trusty and same rake version. 我已经设置了另一个服务器与ubuntu 14.04可靠和相同的rake版本。 The database is still on AWS Aurora RDS with Engine version 5.6.2 and the migration has been completed now. 该数据库仍在AWS Aurora RDS上,引擎版本为5.6.2,现在已完成迁移。

I am not sure if This was the actual problem but the issue has been resolved now. 我不确定这是否是实际问题,但问题现在已经解决了。

Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM