2013-03-13 75 views
0

我試圖迫使其主鍵(id)產生的爲無符號的bigint,通過插入的environment.rb以下:Rails中/ MySQL的無符號長

ActiveRecord::ConnectionAdapters::MysqlAdapter::NATIVE_DATABASE_TYPES[:primary_key] = "BIGINT UNSIGNED DEFAULT NULL auto_increment PRIMARY KEY" 

但是,當我嘗試生成一個遷移,我得到了以下錯誤消息:

/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) "/projects/test/script/rails" generate migration Ball name:string last:string -s 
/projects/test/config/environment.rb:7:in `<top (required)>': uninitialized constant ActiveRecord::ConnectionAdapters::MysqlAdapter (NameError) 
    from /.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!' 
    from /.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.12/lib/rails/commands.rb:25:in `<top (required)>' 
    from /projects/test/script/rails:6:in `require' 
    from /projects/test/script/rails:6:in `<top (required)>' 
    from -e:1:in `load' 
    from -e:1:in `<main>' 

Process finished with exit code 1 

當我把那一行出的environment.rb中,遷移工作,但很明顯的主鍵設置爲int,而不是無符號BIGINT。有任何想法嗎?

+0

的頂部的文件中'配置/ initializers'可能是這更好的地方。 'environment.rb'在加載週期中真的很早。 – tadman 2013-03-13 23:50:03

回答

0

嘗試添加此需要聲明的環境文件

require 'active_record/connection_adapters/mysql_adapter' 
+0

做到了這一點,現在我得到以下錯誤:耙子中止! mysql不是捆綁包的一部分。將它添加到Gemfile。在我的gemfile中,我有gem'mysql2',當我檢查已安裝的gems時,它在那裏:mysql2(0.3.11) – EastsideDeveloper 2013-03-14 00:20:19

+0

您是否從應用程序的根目錄運行'bundle install'? – Benj 2013-03-16 03:41:18