Ruby on rails 不能';t在Rails中的spring更新后运行迁移

Ruby on rails 不能';t在Rails中的spring更新后运行迁移,ruby-on-rails,rails-migrations,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

当我以以下方式运行任何迁移时,我面临一个错误:

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'
因此,通过一些谷歌搜索,我运行了bundle update spring,解决了上述错误,并且我能够删除/添加迁移。同样,如果我运行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
rake中止!
StandardError:发生错误,此迁移和所有后续迁移已取消:
nil的未定义方法“to_sym”: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条堆栈跟踪线**
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in“block(2层)in”
任务: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
预先添加到命令中,如错误消息所示。请参阅下文:

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


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

尝试在终端中运行“bundle update”,然后像往常一样再次尝试“rails控制台”-我遇到了同样的问题,运行bundle update首先为我解决了它

在运行
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
我按照中的建议运行:

spring stop

这为我解决了这个问题。

运行:ps aux | grep spring,然后终止spring进程


这对我很有效。

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

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

gem列表| grep spring

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

gem卸载spring-v'1.3.5'

而且,
bundle
同样,它工作得非常好

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

停止spring服务器

spring stop

你是第一个还是第二个错误。第二个问题是由于
bundle update
,使用
bundle exec
无法修复。要解决第二个问题,您需要将代码还原到从版本控制执行
捆绑包更新之前的某个点。我正在执行相同的操作,当我重新输入add migration命令时,我遇到了以下问题:
spring客户端和服务器之间存在版本不匹配。您应该重新启动服务器,并确保使用相同的版本。客户端:1.3.2,服务器:1.3.3。这是一个私人项目,还是你有一个我可以查看的存储库?实际上你不能访问这个项目。如果您需要代码的任何部分,我会将其粘贴。我会说,捆绑更新通常不是一个好主意,除非您确定所有gem都可以在不破坏东西的情况下进行更新。该问题中还提到了其他有用的建议+1.请注意,这个问题已经提出了半年,而且半年前已有多人提出了完全相同的建议;-)