gpt4 book ai didi

ruby - Rake 迁移错误 - 事件记录中的 "undefined method" "migrate"

转载 作者:行者123 更新时间:2023-12-05 02:11:21 25 4
gpt4 key购买 nike

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

但是,尽管安装了 bundle ,但它拒绝迁移。我得到的错误是 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)

有办法解决这个问题吗?

最佳答案

我遇到了同样的错误,并像这样修复它: https://github.com/padrino/padrino-framework/blob/master/padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb#L131-L137

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

关于ruby - Rake 迁移错误 - 事件记录中的 "undefined method" "migrate",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57618311/

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