1

I am trying to use a Rails 2.3.5 app with Postgres9.1 on Ubuntu (deployed on Apache2 with Phusion Passenger). The app throws this error when I try to access it, complaining that table does not exist:

PGError: ERROR:  relation "users" does not exist
LINE 4:              WHERE a.attrelid = '"users"'::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 = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

However if I cut and paste the same query at the psql (cmdline-client), it works just fine. The users table exists too. I tried a rake db:reset and 'rake db:migrate' again and again but it doesn't seem to help.
I also verified that the ActiveRecord::Base.connection succeeds from the script/console in the rails-appwhich means the connection to the database works with the credentials configured in database.yml.

I am lost.. any clues to remedy this will be appreciated greatly.

3
  • 2
    My bet is, that you are connecting to a different DB from within Rails Commented Nov 3, 2011 at 22:15
  • Thanks much for your response, Edwin and "a_horse..". T'was connection to wrong DB. I'd configured the app for development mode (via environment.rb). But my setting was being overridden by Phusion Passenger (which I was using with apache); it sets the RailsEnv to 'production' by default. Since I'd earlier used 'rake db:create:all', the prod DB did get created but my 'rake db:migrate' only populated the development DB. I had to change the apache site configuration to set RailsEnv development as shown here: modrails.com/documentation/…. Commented Nov 4, 2011 at 21:45
  • @Don: a_horse_with_no_name had his money on the right horse. Cool that it works. I do wonder about this mysterious Edwin guy, though. ;) Commented Nov 4, 2011 at 21:56

1 Answer 1

1

Three possible causes:

  1. The special cast ::regclass takes the current setting for search_path into account. Maybe your table users is in a schema that is not in the search_path when querying from your app. search_path can be set per user or session.
    Solution would be to schema-qualify the table-name like this:

    'myschema.users'::regclass

  2. Capitalization. Why '"users"'::regclass and not 'users'::regclass? This is redundant. Is the actual name of the Table "Users" or something and you use upper case in psql? (If you actually cut & paste the query, this can't be it.)

  3. Connection to the wrong database. Wrong port?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks much for your response, Edwin and "a_horse..". T'was connection to wrong DB. I'd configured the app for development mode (via environment.rb). But my setting was being overridden by Phusion Passenger (which I was using with apache); it sets the RailsEnv to 'production' by default. Since I'd earlier used 'rake db:create:all', the prod DB did get created but my 'rake db:migrate' only populated the development DB. I had to change the apache site configuration to set RailsEnv development as shown here: modrails.com/documentation/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.