rspec返回“ PG ::错误:错误:关系” table

编程入门 行业动态 更新时间:2024-10-25 08:20:48
本文介绍了rspec返回“ PG ::错误:错误:关系” table_name”;不存在”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在rvm,rspec 2.8.0,rails 3.0.6和pg 0.13.2上,环境是REE(2011.12)。在CentOS 5.6上使用PostgreSQL 8.3.17。 db:migrate可以正常工作。但是rspec出现以下错误。

Environment is REE(2011.12) on rvm, rspec 2.8.0, rails 3.0.6, and pg 0.13.2. Using PostgreSQL 8.3.17 on CentOS 5.6. The db:migrate have work correctly. But rspec have got following error.

1) ApiController articles OK Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: PG::Error: ERROR: relation "table_name" does not exist : DELETE FROM "table_name"

我将我的项目从具有rspec 1.x系列的rails 2.3.5更新到具有rspec2的rails 3.0。复制了所有的rspec测试,然后我将旧的spec_helper.rb和新的合并(它是 rails g rspec:install 生成的)。

I'm updating my project from rails 2.3.5 with rspec 1.x series to rails 3.0 with rspec2. Copied all rspec tests, and I have merged old spec_helper.rb and new one(It was generated rails g rspec:install).

ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true end

我读到与此错误类似的问题。所以我尝试了 rake db:test:prepare 或 rake db:test:load ,但这无法解决。你有什么主意吗? 似乎测试尚未在测试数据库上运行...我该怎么办? :(

I read similar question about this error.So I tried rake db:test:prepare or rake db:test:load, But It's not resolve. Do you have any idea? It looks like the test hasn't run on test database... How do I do? :(

推荐答案

我在两个实例中遇到了这个问题(2012年6月13日更新):

I've run into this in two instances (updated 6/13/2012):

我尚未迁移测试数据库...

I haven't yet migrated my test database...

rake db:migrate

...在两个 db:test:prepare 和 db:test:load 。

何时您调用rspec还是应该为您的数据库准备和 load 准备数据库。您不必手动进行此操作

When you invoke rspec it should prepare and load your database for you anyway. You shouldn't have to do that by hand.

迁移过程中的错字:我不小心颠倒了参数中的表名和列名列表。

A typo in my migration. I accidentally reversed my table and column names in the parameter list.

在Rails 3.1项目上的迁移:

A migration on a Rails 3.1 project:

def change add_column :had_import_errors, :studies, :boolean, :default => false add_column :import_data_cache, :studies, :text end

...这是错误的,因为有导入错误和 import_data_cache 是我的列名,因此应该排第二,而不是第一。

...which is wrong, because has_import_errors and import_data_cache are my column names, and they therefore should come second, not first.

正确的迁移表名首先是:

The correct migration, with the table name first was:

def change add_column :studies, :had_import_errors, :boolean, :default => false add_column :studies, :import_data_cache, :text end

更多推荐

rspec返回“ PG ::错误:错误:关系” table

本文发布于:2023-10-14 11:53:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1490983.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   关系   rspec   PG   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!