瑞克迁移错误-活动记录中的“未定义方法”“迁移”

时间:2019-08-22 23:59:09

标签: ruby migration rakefile

系统:Windows 10 使用:Ruby的当前版本 我试图按照https://github.com/piedoom/tumbot

上的说明来运行tumbot

但是,尽管安装了捆绑软件,它还是拒绝迁移。我得到的错误是 https://66.media.tumblr.com/029bbd52eda91c2ffbac01f7c8af467d/27d62997ece87db2-48/s540x810/4c5b63b9acfbd7495342cb667fc8c78236964d60.png

C:\Users\QueenBee>rake migrate
rake aborted!
NoMethodError: undefined method `migrate' for ActiveRecord::Migrator:Class
C:/Users/QueenBee/Rakefile:9:in `block in <top (required)>'
Tasks: TOP => migrate
(See full trace by running task with --trace)

内部的rake文件如下所示 https://66.media.tumblr.com/1b6f54503a7b2c5d91c43ae5a2801988/27d62997ece87db2-9c/s540x810/172efac954b66f4dc77980a3e2fdfda0b529be71

require 'active_record'
require 'yaml'
require 'logger'

task :default => :migrate

desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
      ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
end

task :environment do
      ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml')))
          ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
end

我已经卸载,重新安装并更新了rake文件,到目前为止还没有找到它。

这是已安装的gem包

C:\Users\QueenBee>bundle install
Fetching gem metadata from https://rubygems.org/.......
Resolving dependencies...
Using concurrent-ruby 1.1.5
Using i18n 1.6.0
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using zeitwerk 2.1.9
Using activesupport 6.0.0
Using activemodel 6.0.0
Using activerecord 6.0.0
Using bundler 1.17.2
Using chunky_png 1.3.11
Using coderay 1.1.2
Using multipart-post 2.1.1
Using faraday 0.9.2
Using faraday_middleware 0.9.2
Using json 2.2.0
Using msgpack 1.3.1 (x64-mingw32)
Using marky_markov 0.3.5
Using method_source 0.9.2
Using mime-types-data 3.2019.0331
Using mime-types 3.2.2
Using mini_magick 4.9.5
Using mini_portile2 2.4.0
Using nokogiri 1.10.4 (x64-mingw32)
Using oauth 0.5.4
Using oily_png 1.2.1
Using pry 0.12.2
Using thor 0.20.3
Using pxlsrt 1.8.2
Using sentimental 1.5.0
Using simple_oauth 0.3.1
Using sqlite3 1.4.1
Using tumblr_client 0.8.5
Bundle complete! 9 Gemfile dependencies, 33 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

更新:我在活动记录上切换到5.0,并且遇到了另一个问题...

C:\Users\QueenBee>rake migrate
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
rake aborted!
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'

Caused by:
Gem::MissingSpecVersionError: Could not find 'sqlite3' (~> 1.3.6) - did find: [sqlite3-1.4.1]
Checked in 'GEM_PATH=C:/Users/QueenBee/.gem/ruby/2.6.0;C:/Ruby26-x64/lib/ruby/gems/2.6.0', execute `gem env` for more information
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'

Caused by:
Gem::MissingSpecVersionError: Could not find 'sqlite3' (~> 1.3.6) - did find: [sqlite3-1.4.1]
Checked in 'GEM_PATH=C:/Users/QueenBee/.gem/ruby/2.6.0;C:/Ruby26-x64/lib/ruby/gems/2.6.0', execute `gem env` for more information
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'
Tasks: TOP => migrate => environment
(See full trace by running task with --trace)

当我尝试使用DL Sqlite3(1.3.6)时,我收到了此消息

C:\Users\QueenBee>gem install sqlite3 -v 1.3.6
Fetching sqlite3-1.3.6.gem
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.3.6/ext/sqlite3
C:/Ruby26-x64/bin/ruby.exe -I C:/Ruby26-x64/lib/ruby/2.6.0 -r ./siteconf20190822-9996-q7b2yp.rb extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... yes
checking for sqlite3_backup_init()... yes
checking for sqlite3_column_database_name()... yes
checking for sqlite3_enable_load_extension()... yes
checking for sqlite3_load_extension()... yes
checking for sqlite3_open_v2()... yes
checking for sqlite3_prepare_v2()... yes
checking for sqlite3_int64 in sqlite3.h... yes
checking for sqlite3_uint64 in sqlite3.h... yes
creating Makefile

current directory: C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.3.6/ext/sqlite3
make "DESTDIR=" clean

当我尝试使用下一个工作版本(1.3.8)时,出现此错误

C:\Users\QueenBee>rake migrate
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
rake aborted!
LoadError: Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'

Caused by:
LoadError: cannot load such file -- sqlite3/sqlite3_native
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'

Caused by:
LoadError: cannot load such file -- sqlite3/2.6/sqlite3_native
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'
Tasks: TOP => migrate => environment
(See full trace by running task with --trace)

C:\Users\QueenBee>rake migrate
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
rake aborted!
LoadError: Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'

Caused by:
LoadError: cannot load such file -- sqlite3/sqlite3_native
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'

Caused by:
LoadError: cannot load such file -- sqlite3/2.6/sqlite3_native
C:/Users/QueenBee/Rakefile:13:in `block in <top (required)>'
Tasks: TOP => migrate => environment
(See full trace by running task with --trace)

反正有解决此问题的方法吗?

1 个答案:

答案 0 :(得分:3)

我遇到了相同的错误,并按以下方式修复: https://github.com/padrino/padrino-framework/blob/master/padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb#L131-L137

ActiveRecord::Migrator.migrate似乎已过时。

相关问题