在 Rails spring 更新后无法 运行 迁移

Couldn't run migration after spring update in Rails

我在 运行 任何迁移时遇到错误:

raj@notebook-pc:~/Desktop/Projects/invoicemanagement$ rails g migration RemoveDescriptionOfGoodsFromInvoiceDetails description_of_goods:string
Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
/var/lib/gems/1.9.1/gems/bundler-1.9.0/lib/bundler/runtime.rb:34:in `block in setup': You have already activated spring 1.3.3, but your Gemfile requires spring 1.3.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
    from /var/lib/gems/1.9.1/gems/bundler-1.9.0/lib/bundler/runtime.rb:19:in `setup'

    ** 11 stack trace lines skipped **

    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'

所以通过一些谷歌搜索,我 运行 捆绑更新 spring,解决了上述错误,我能够 remove/add 迁移.同样,如果我 运行 rake db:migrate,我会收到错误消息:

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `to_sym' for nil:NilClass/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:216:in `column'

    ** 33 stack trace lines skipped **

/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate

请帮帮我

发生这种情况是因为您的项目的依赖项之一是 Spring 的旧版本,而不是安装在您系统上的版本:

You have already activated spring 1.3.3, but your Gemfile requires spring 1.3.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

处理此问题的正确方法是在您的命令前添加 bundle exec,如错误消息所示。请看下面:

When running an executable, ALWAYS use bundle exec [command]. Quoting from the bundler documentation: In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle. However, this is unreliable and is the source of considerable pain.

http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/

运行 bundle update 可能会导致一些其他问题。如果您的第二个错误仍然存​​在,您可能想从版本控制恢复到旧的 Gemfile

在您的终端中尝试 运行 "bundle update",然后像往常一样再次尝试 "rails console" - 我遇到了同样的问题,运行 捆绑包更新首先为我修复了它!

在 运行 bundle update 和更新 Spring 之后,我在 运行 控制台时收到以下错误:

There is a version mismatch between the spring client and the server.
You should restart the server and make sure to use the same version.

CLIENT: 1.3.4, SERVER: 1.3.3

我遵循了 this Github issue 和 运行 中的建议:

spring stop

这解决了我的问题。

运行: ps 辅助 | grep spring,然后终止 spring 进程。

对我有用。

我在尝试 运行 rails 我的 docker 容器外的命令时遇到了类似的问题。

在我的例子中,我的 Gemfile.lock 文件说要使用 Spring (1.3.4),但错误消息说我的服务器是 运行ning 版本 1.3.5。在我的命令前加上 bundle exec 也没有任何区别。通过 运行宁

gem list | grep spring

我注意到我安装了多个版本。在我运行

之后

gem uninstall spring -v '1.3.5'

bundle 再次,它完美地工作。

谁知道,我可能在某个时间需要其他项目的较新版本。

停止 spring 服务器

spring stop