0

I want to get a rails application working with PostgreSQL, but something strange is happening. My friends were able to install PostgreSQL and execute:

sudo su
su postgres
createdb development

followed by

rails server

with no bugs. However, when I try to do that, I get a strange error:

/Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord 3.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `async_exec': PG::Error: ERROR:  relation "reports" does not exist (ActiveRecord::StatementInvalid) 

LINE 4:              WHERE a.attrelid = '"reports"'::regclass
                                    ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
          FROM pg_attribute a LEFT JOIN pg_attrdef d
            ON a.attrelid = d.adrelid AND a.attnum = d.adnum
         WHERE a.attrelid = '"reports"'::regclass
           AND a.attnum > 0 AND NOT a.attisdropped
         ORDER BY a.attnum

Note that "reports" is a model in the application.

For what it's worth, the database.yml file looks like this:

development:
  adapter: postgresql
  encoding: unicode
  database: development
  pool: 5
  username: postgres
  password: post

(I don't know what pool means, but I have already set my postgres password to be post)

kyothine
  • 296
  • 2
  • 19
  • Do you have any initializers that do anything with your models? – mu is too short Jun 29 '12 at 02:00
  • what do you mean by that? i don't think so – kyothine Jun 29 '12 at 02:55
  • 1
    Sounds like something in your application initialization is trying to use your `Report` class. That SQL is what ActiveRecord's PostgreSQL adapter uses to figure out the structure of a table and the error indicates that you don't have `reports` in your database. When you `rake db:migrate`, you get the same problem; therefore your application initialization is probably at fault as that happens *before* `db:migrate` does anything useful. What plugins are you using? Do you have anything in `config/initializers`? – mu is too short Jun 29 '12 at 03:17
  • Thanks for the answer. This is an interesting idea. I do have some stuff in config/initializers. Should I look for files that reference the Report class? – kyothine Jun 29 '12 at 16:50
  • 1
    Hard to say, the reference to Reports could be hidden behind a search. I have seen ActiveAdmin involved in this sort of problem before but I don't use it so that's just wild speculation. – mu is too short Jun 29 '12 at 17:38
  • The app actually does have ActiveAdmin installed. Do you happen to have a link to a problem like that? I'm going to continue trying to fix this. – kyothine Jun 29 '12 at 19:48
  • You could try disabling ActiveAdmin, then do your `db:migrate`, then re-enable ActiveAdmin. – mu is too short Jun 29 '12 at 20:00

2 Answers2

2

Have you run rake db:migrate?

Rob d'Apice
  • 2,416
  • 1
  • 19
  • 29
  • it gives me the same error when i try rake db:migrate -- rake aborted! PG::Error: ERROR: relation "reports" does not exist....etc – kyothine Jun 29 '12 at 01:45
  • what about rake db:reset or rake db:drop & rake db:create (warning: you'll lose any data in your local database if you had any!) – Rob d'Apice Jun 29 '12 at 01:47
  • rake db:drop and rake db:create seem to do nothing, as when i run "rake db:reset" it still gives me the rake aborted! error. – kyothine Jun 29 '12 at 01:53
  • Try naming your database something else in yml file, then run db:create, db:migrate – house9 Jun 29 '12 at 02:04
  • that does not seem to be working either. i heard that this might be fixable if i created the reports table manually -- but do you know how i could go about doing that? – kyothine Jun 29 '12 at 02:17
  • Create a new rails app and try starting over – house9 Jun 29 '12 at 03:19
  • This ended up being my issue. – zkwentz Mar 30 '13 at 23:29
0

WHERE a.attrelid = '"reports"'::regclass ... has too many quotes. It should be WHERE a.attrelid = 'reports'::regclass ...

wildplasser
  • 43,142
  • 8
  • 66
  • 109
  • Interesting -- do you know which file this should be in? I'm going to try to correct it – kyothine Jun 29 '12 at 15:09
  • I'm sorry, I don't know RoR. Probably it assumes somehow that 'reports' is a tablename or column name, but in this context it is a string literal. – wildplasser Jun 29 '12 at 15:36
  • 1
    The quotes are fine, the SQL in question is ActiveRecord's version of `\d reports` but the table isn't there yet so the cast fails. This is a chicken'n'egg problem in the application initialization phase. – mu is too short Jun 29 '12 at 17:36