无法执行“rails db:*”之类的命令

问题描述 投票:0回答:1

我目前正在使用Ruby on rails写一个网站几个月。

突然(5或6天前),所有的命令,如rails db:migraterails db:rollbackrails db:*“不再起作用了(它似乎没有触及任何东西......)。

我试图重新安装宝石rakerailsrailsties(已经在他们的最新版本中),但问题仍然存在。

My Gemfile

执行命令rails db:migrate时的结果:

rails aborted!
Don't know how to build task 'db:migrate' (See the list of available tasks with `rake --tasks`)
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)

执行命令rake db:migrate时的结果:

rake aborted!
Don't know how to build task 'db:migrate' (See the list of available tasks with `rake --tasks`)
/usr/local/rvm/gems/ruby-2.5.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
(See full trace by running task with --trace)

执行命令rails --tasks --all时的结果:

rails app:template                       # Applies the template supplied by LOCATION=(/path/t...
rails app:templates:copy                 #
rails app:update                         # Update configs and some other initially generated ...
rails app:update:bin                     #
rails app:update:configs                 #
rails app:update:upgrade_guide_info      #
rails assets:clean[keep]                 # Remove old compiled assets
rails assets:clobber                     # Remove compiled assets
rails assets:environment                 # Load asset compile environment
rails assets:precompile                  # Compile all the assets named in config.assets.prec...
rails autoprefixer:info                  # Show selected browsers and prefixed CSS properties...
rails cache_digests:dependencies         # Lookup first-level dependencies for TEMPLATE (like...
rails cache_digests:nested_dependencies  # Lookup nested dependencies for TEMPLATE (like mess...
rails default                            #
rails dev:cache                          # Toggle development mode caching on/off
rails environment                        #
rails initializers                       # Print out all defined initializers in the order th...
rails log:clear                          # Truncates all/specified *.log files in log/ to zer...
rails middleware                         # Prints out your Rack middleware stack
rails notes                              # Enumerate all annotations (use notes:optimize, :fi...
rails notes:custom                       # Enumerate a custom annotation, specify with ANNOTA...
rails notes:fixme                        #
rails notes:optimize                     #
rails notes:todo                         #
rails restart                            # Restart app by touching tmp/restart.txt
rails routes                             # Print out all defined routes in match order, with ...
rails secret                             # Generate a cryptographically secure secret key (th...
rails stats                              # Report code statistics (KLOCs, etc) from the appli...
rails test                               # Runs all tests in test folder except system ones
rails test:controllers                   #
rails test:db                            # Run tests quickly, but also reset db
rails test:functionals                   #
rails test:generators                    #
rails test:helpers                       #
rails test:integration                   #
rails test:jobs                          #
rails test:mailers                       #
rails test:models                        #
rails test:prepare                       #
rails test:run                           #
rails test:system                        # Run system tests only
rails test:units                         #
rails time:zones[country_or_offset]      # List all time zones, list by two-letter country co...
rails time:zones:all                     #
rails time:zones:local                   #
rails time:zones:us                      #
rails tmp                                #
rails tmp/cache                          #
rails tmp/cache/assets                   #
rails tmp/pids                           #
rails tmp/sockets                        #
rails tmp:cache:clear                    #
rails tmp:clear                          # Clear cache, socket and screenshot files from tmp/...
rails tmp:create                         # Creates tmp directories for cache, sockets, and pids
rails tmp:pids:clear                     #
rails tmp:screenshots:clear              #
rails tmp:sockets:clear                  #
rails yarn:install                       # Install all JavaScript dependencies as specified v...

如果你能帮我解决这个问题,我将非常感激!

先感谢您 !

奥勒留

ruby-on-rails ruby ruby-on-rails-5
1个回答
0
投票

这可能是由于ruby版本升级所致。尝试使用bundle install再次安装宝石,然后再试一次。如果不工作,你需要运行bundle exec rails db:migrate捆绑选择正确版本的宝石。

编辑:因为你正在使用rvm,请确保你使用相同的Ruby版本。看看这个https://rvm.io/workflow/projects并确保你的版本正确。提示:检查Gemfile中的Ruby版本,因为它可能是您的问题的根源。

© www.soinside.com 2019 - 2024. All rights reserved.