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

时间:2019-01-18 10:05:42

标签: ruby-on-rails ruby ruby-on-rails-5

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

突然(5或6天前),所有命令,例如rails db:migraterails db:rollbackrails db:*“都不再起作用(并且似乎没有任何作用。 ..)。

我尝试重新安装gems 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...

如果您能帮助我解决这个问题,我将不胜感激!

提前谢谢!

Aurèle

1 个答案:

答案 0 :(得分:0)

这可能是由于ruby版本升级引起的。 尝试使用bundle install重新安装gem,然后重试。 如果不起作用,则需要以bundle exec rails db:migrate的身份运行,以选择正确的宝石版本。

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