0

我试图通过在 environment.rb 中插入以下内容来强制将主键(id)生成为 unsigned bigint:

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,而不是 unsigned bigint。有任何想法吗?

4

1 回答 1

0

尝试在您的环境文件顶部添加此 require 语句

require 'active_record/connection_adapters/mysql_adapter'
于 2013-03-13T23:48:03.607 回答