在Rails中弹出更新后无法运行迁移

时间:2015-03-23 04:27:27

标签: ruby-on-rails rails-migrations

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

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'

所以通过一些谷歌搜索我运行捆绑更新弹簧,这解决了上述错误,我能够删除/添加迁移。再次,如果我运行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

请帮帮我。

6 个答案:

答案 0 :(得分:28)

运行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

这解决了我的问题。

答案 1 :(得分:3)

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

答案 2 :(得分:2)

运行:ps aux | grep spring,然后杀死spring过程。

它对我有用。

答案 3 :(得分:2)

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

在我的情况下,我的Gemfile.lock文件说使用Spring(1.3.4),但错误消息说我的服务器运行的是1.3.5版本。在bundle exec之前添加命令也没有任何区别。通过运行

gem list | grep spring

我注意到我安装了多个版本。我跑完后

gem uninstall spring -v '1.3.5'

再次

bundle,它运作得很好。

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

答案 4 :(得分:1)

这是因为项目的某个依赖项是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,如错误消息所示。请参阅以下内容:

  

运行可执行文件时,总是使用bundle exec [command]。从捆绑器文档引用:在某些情况下,如果可执行文件恰好安装在您的系统中并且没有引入任何与您的捆绑包冲突的gem,则运行不带bundle exec的可执行文件可能会起作用。然而,这是不可靠的,并且是相当痛苦的根源。

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

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

答案 5 :(得分:0)

停止弹簧服务器

spring stop