耙子流产了! NameError:使用rake db:migrate时未初始化的常量ActiveRecord :: VERSION错误

时间:2019-02-21 05:42:23

标签: ruby-on-rails ruby rake

我刚接触红宝石。我想在本地系统上重新创建生产设置以进行开发。在数据库迁移期间,我似乎遇到了问题。

我正在使用Ubuntu 18.04 OS。我已经成功安装了mysql-server,ruby 2.3.2,rails 5.0,libmysqld-dev和mysql2 gem。我能够创建数据库并导入用于表创建的SQL文件。要进行挂起的迁移,我执行了rake db:migrate。我收到以下错误。

rake aborted!NameError: uninitialized constant ActiveRecord::VERSION
/home/raj/.rvm/gems/ruby-2.3.2/gems/activerecord-session_store-1.1.1/lib/action_dispatch/session/active_record_store.rb:151:in `<top (required)>'
/home/raj/.rvm/gems/ruby-2.3.2/gems/activerecord-session_store-1.1.1/lib/active_record/session_store.rb:2:in `require'
/home/raj/.rvm/gems/ruby-2.3.2/gems/activerecord-session_store-1.1.1/lib/active_record/session_store.rb:2:in `<top (required)>'
/home/raj/.rvm/gems/ruby-2.3.2/gems/activerecord-session_store-1.1.1/lib/activerecord/session_store.rb:1:in `require'
/home/raj/.rvm/gems/ruby-2.3.2/gems/activerecord-session_store-1.1.1/lib/activerecord/session_store.rb:1:in `<top (required)>'
/home/raj/IRIS/config/application.rb:7:in `<top (required)>'
/home/raj/IRIS/Rakefile:4:in `require'
/home/raj/IRIS/Rakefile:4:in `<top (required)>'
/home/raj/.rvm/gems/ruby-2.3.2/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/raj/.rvm/gems/ruby-2.3.2/bin/ruby_executable_hooks:24:in `eval'
/home/raj/.rvm/gems/ruby-2.3.2/bin/ruby_executable_hooks:24:in `<main>'
 LoadError: cannot load such file -- activerecord-session_store
/home/raj/IRIS/config/application.rb:7:in `<top (required)>'
/home/raj/IRIS/Rakefile:4:in `require'
/home/raj/IRIS/Rakefile:4:in `<top (required)>'
/home/raj/.rvm/gems/ruby-2.3.2/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/raj/.rvm/gems/ruby-2.3.2/bin/ruby_executable_hooks:24:in `eval'
/home/raj/.rvm/gems/ruby-2.3.2/bin/ruby_executable_hooks:24:in `<main>'
(See full trace by running task with --trace)

关于active_record_store.rb行号151中的错误,代码如下:

if ActiveRecord::VERSION::MAJOR == 4
    require 'action_dispatch/session/legacy_support'
    ActionDispatch::Session::ActiveRecordStore.send(:include, ActionDispatch::Session::LegacySupport)
end

3 个答案:

答案 0 :(得分:0)

尝试运行以下提到的命令

gem install activerecord

希望这会有所帮助。

答案 1 :(得分:0)

您可以将其添加到active_record_store.rb的顶部以查看其是否有效吗?

require 'active_record/version'

答案 2 :(得分:0)

在RVM安装导轨期间,还以某种方式安装了最新版本。删除所有的宝石并执行$ gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 $ gcc -o test -Wall -std=c11 a.c b.c 即可。