gpt4 book ai didi

mysql - add_index 迁移失败,返回 "Argument out of range"

转载 作者:可可西里 更新时间:2023-11-01 08:55:49 24 4
gpt4 key购买 nike

我正在尝试在另一台计算机上复制(正在运行!)Rails 3/MySql 应用程序。我创建了一个 schema.rb 和 data.yml,然后使用了 db:schema:load 和 db:data:load,除一件事外,它们都运行良好。我的表上有许多索引,但 rake 尝试创建它们失败了——我不得不从 schema.rb 中注释它们以使其生成,所以我尝试将它们放入迁移中(它们的创建方式是原来的应用程序!)和 rake 仍然死了。这是错误消息:

O:\Development\myapp>rake db:migrate
rake aborted!
An error has occurred, all later migrations canceled:

argument out of range

C:/Ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:446:in `utc'
C:/Ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:446:in `each'
C:/Ruby/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:446:in `indexes'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:406:in `index_name_exists?'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:343:in `add_index'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:383:in `block in method_missing'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:359:in `block in say_with_time'
C:/Ruby/lib/ruby/1.9.1/benchmark.rb:294:in `measure'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:359:in `say_with_time'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:379:in `method_missing'O:/Development/codenotes/db/migrate/20110114212538_add_notes_index.rb:11:in `up'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:312:in `block in migrate'
C:/Ruby/lib/ruby/1.9.1/benchmark.rb:294:in `measure'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:312:in `migrate'
C:in `migrate'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:537:in `block (2 levels) in migrate'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:613:in `call'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:613:in `ddl_transaction'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:536:in `block in migrate'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:523:in `each'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:523:in `migrate'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:433:in `up'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/migration.rb:415:in `migrate'
C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:142:in `block (2 levels) in <top (required)>'
C:/Ruby/lib/ruby/1.9.1/rake.rb:634:in `call'
C:/Ruby/lib/ruby/1.9.1/rake.rb:634:in `block in execute'
C:/Ruby/lib/ruby/1.9.1/rake.rb:629:in `each'
C:/Ruby/lib/ruby/1.9.1/rake.rb:629:in `execute'
C:/Ruby/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain'
C:/Ruby/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
C:/Ruby/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain'
C:/Ruby/lib/ruby/1.9.1/rake.rb:581:in `invoke'
C:/Ruby/lib/ruby/1.9.1/rake.rb:2041:in `invoke_task'
C:/Ruby/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level'
C:/Ruby/lib/ruby/1.9.1/rake.rb:2019:in `each'
C:/Ruby/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level'
C:/Ruby/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
C:/Ruby/lib/ruby/1.9.1/rake.rb:2013:in `top_level'
C:/Ruby/lib/ruby/1.9.1/rake.rb:1992:in `run'
C:/Ruby/bin/rake:31:in `<main>'

这是有问题的迁移:

class AddNotesIndex < ActiveRecord::Migration
def self.up
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :unlock_token, :unique => true
end

def self.down
remove_index :users, :email, :unique => true
remove_index :users, :reset_password_token, :unique => true
remove_index :users, :confirmation_token, :unique => true
remove_index :users, :unlock_token, :unique => true
end
end

这与我在原始应用程序中创建索引所用的代码完全相同。据我所知,我在这台计算机上运行完全相同的环境——Ruby 1.9.2、Rails 3.0.3、mysql2 0.2.6 x86-mingw32、MySQL 5.1.41。我什至复制了同一个 libmysql.dll。我很难过。

编辑

哈哈,我傻了。我正在更新 MySQL\MySQL Server 5.1\bin 中的 libmysql.dll 而不是 Ruby\bin 中的那个。将最新版本复制到 Ruby\bin 后,一切正常。谢谢大家!

最佳答案

好像很多人都有这个问题,包括我。该错误似乎源自 mysql2 gem。所以对我有用的是:

  1. 安装 mysql gem
  2. 在Gemfile中从mysql2改成mysql
  3. 在 database.yml 中将适配器从 mysql2 更改为 mysql

如果最后创建的表是在与调用 add_index 的同一迁移中创建的,那么可能会删除最后创建的表,因为它将尝试再次创建它。

也许更多的是解决方法而不是解决方案,但我还没有遇到任何更好的方法。

关于mysql - add_index 迁移失败,返回 "Argument out of range",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4697442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com