1

I deployed an app that uses ActiveRecord to Heroku, and I got an internal server error. It works fine on my local machine (where the database is SQLite). Below is the log message for the error. The newsletters table is just a table with no associations. It's got just one field for email addresses. I don't know PostgreSQL, and I'm not sure what the problem is with this.

"ActiveRecord::StatementInvalid - PGError: ERROR:  relation "newsletters" does not exist
:             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 = '"newsletters"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
:

This is the code that gets called when the error appears.

  post :index, :map => "/newsletter" do
    email=params[:email]
    @signup=Newsletter.new(:email=>email)
    render "newsletter/index",:layout => false
  end
picardo
  • 24,530
  • 33
  • 104
  • 151

3 Answers3

1

I think Heroku will find your local database so you just have to write:

heroku db:push

And if you want to fetch data from the server:

heroku db:pull
Alfred
  • 7,071
  • 4
  • 27
  • 35
0

I fixed my problem. All I had to was heroku db:push sqlite://db/local.db

picardo
  • 24,530
  • 33
  • 104
  • 151
0

The root of this problem is that ActiveRecord is trying to understand the structure of a given table through something called a "catalog query." This is a query against the database's metadata relations to understand what is going on in there.

This query assumes the relation already exists, and because it did not, it blew up with a cryptic message. This is probably falls into the region of "report this to ActiveRecord" (if not already fixed) as sub-ideal error messaging in a somewhat common failure case.

fdr
  • 447
  • 2
  • 6