必须在 bundle exec 前加上 rake db:migrate

Must prepend bundle exec to rake db:migrate

我不知道发生了什么,但是当我创建一个新模型并想要 运行 rake db:migrate 但它给了我这个错误:

rake aborted! Gem::LoadError: You have already activated rake 11.0.1, but your Gemfile requires rake 10.5.0. Prepending bundle exec to your command may solve this.

我相信我没有对 gem 进行任何更新。我告诉我在执行耙子之前预先添加 bundle exec 但我只想像以前一样 运行 rake db:migrate

如何使我的本地系统 rake gem 版本适合我的 rails rake gem 版本?

尝试在 rake db:migrate 命令前加上 bundle exec 前缀。

bundle exec rake db:migrate

您的系统 gem 与 gem 文件中的系统存在冲突。看起来您的本地系统使用的是 rake 11.0.1,但您的 rails 版本使用的是 10.5.0.

有两种方法可以解决这个问题:

1) 使用bundle exec rake db:migrate。这将在 gem 文件中指定的 gems 的上下文中执行 rake 任务。 (参见 http://bundler.io/man/bundle-exec.1.html

2) 更新您的系统 gem 以便它们与您的 gem 文件中指定的匹配。

两者中,1) 是更简单的选项。

您可以按照以下步骤解决此 rake 版本冲突。

  1. 使用命令 gem uninstall rake

  2. 卸载 rake
  3. 使用命令gem install rake --version 10.5.0

  4. 安装特定的rake版本

您还可以将 Gemfile 中的佣金版本更新为 11.0.1

此外,如果您使用 rvm,请确保当您使用不同的 ruby 版本时切换 gemsets 时 rake 版本不会改变。

发生这种情况是因为 Rake 11.0.1 在您的系统中可用,但您的 Rails 应用正在使用 Rake 10.5.0。

您的应用使用 Gemfile.lock 文件中指定的 gem,该文件是您首次 运行 bundle install.

时由 Bundler 创建的

更新您的 Gem 可以解决此问题。根据 Bundler docs

Run the command bundle update to update your gems.
Bundler will update the Gemfile.lock file for you.