0

I have been in trouble with this error caused when I started to code my tests on ruby on rails.

I have search in the web but the posts that I have found did not help me. I leave the references:

Rails: Relation does not exist for reference with class name in production

https://github.com/rails/rails/issues/29206

PG undefinedtable error relation users does not exist

This is the test that I made: App/test/models/material_test.rb

require 'test_helper'

class MaterialTest < ActiveSupport::TestCase
  test "the truth" do
   assert true
  end
end

When I try to execute it using:

rails test

I got the following error:

# Running:

E

Error:
CategoriesControllerTest#test_the_truth:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "object_formats" does not exist
LINE 8:                WHERE a.attrelid = '"object_formats"'::regcla...
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
                     c.collname, col_description(a.attrelid, a.attnum) AS comment
                FROM pg_attribute a
                LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                LEFT JOIN pg_type t ON a.atttypid = t.oid
                LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
               WHERE a.attrelid = '"object_formats"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum


My repo is public and the code is up to date.

https://github.com/FragmentX/FRAGMENTX

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    Did you run `rake db:test:prepare`? – jvillian Oct 01 '19 at 18:07
  • That SQL is what ActiveRecord uses to figure out the structure of the `object_formats` table (AKA the `ObjectFormat` model in `app/models/object_format.rb`). The error is telling out that there is no `object_formats` table, hence jillian's suggestion. – mu is too short Oct 01 '19 at 18:13
  • Yes, I have tried to do "rails db:test:prepare" @jvillian – Carlos Duran Roca Oct 01 '19 at 19:44
  • @muistooshort I do not know hot to avoid to telling out that there is no object_formats – Carlos Duran Roca Oct 01 '19 at 19:45
  • Ok, thanks to the advice od the @muistooshort I think I have solved the problem. The fixtures file where empty/messy and with bad information about the models and issues I had to test. Once I have deleted all the fixtures folder the program started to run the dummy tests. I will report on Thursday the final report – Carlos Duran Roca Oct 01 '19 at 20:14
  • there must be some issue with your schema.rb file – Jagdish Oct 02 '19 at 07:54

0 Answers0