开发者

Heroku Push Problem part 2 - Postgresql - PGError Relations does not exist - Ruby on Rails

Ok so got through my last problem with the difference between Postgresql and开发者_Python百科 SQLite and seems like Heroku is telling me I have another one. I am new to ruby and rails so a lot of this stuff I can't decipher at first. Looking for a little direction here. The error message and PostsController Index are below. I checked my routes.rb file and all seems well there but I could be missing something. I will post if you need.

Processing PostsController#index (for 99.7.50.140 at 2010-04-23 15:19:22) [GET]

ActiveRecord::StatementInvalid (PGError: ERROR:  relation "tags" 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 = '"tags"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
):

PostsController#index

  def index
    @tag_counts = Tag.count(:group => :tag_name, 
       :order => 'count_all DESC', :limit => 20)
       conditions, joins = {}, :votes

    @ugtag_counts = Ugtag.count(:group => :ugctag_name, 
       :order => 'count_all DESC', :limit => 20)
       conditions, joins = {}, :votes

    @vote_counts = Vote.count(:group => :post_title, 
          :order => 'count_all DESC', :limit => 20)
          conditions, joins = {}, :votes


       unless(params[:tag_name] || "").empty?
         conditions = ["tags.tag_name = ? ", params[:tag_name]]
         joins = [:tags, :votes]
       end
       @posts=Post.paginate(
                 :select => "posts.*, count(*) as vote_total", 
                 :joins => joins, 
                 :conditions=> conditions, 
                 :group => "votes.post_id, posts.id ", 
                 :order => "created_at DESC",
                 :page => params[:page], :per_page => 5)
        @popular_posts=Post.paginate(
                 :select => "posts.*, count(*) as vote_total", 
                 :joins => joins, 
                 :conditions=> conditions, 
                 :group => "votes.post_id, posts.id", 
                 :order => "vote_total DESC",
                 :page => params[:page], :per_page => 3)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @posts }
      format.json { render :json => @posts }
      format.atom
    end
  end


I was running into a similar "PGError: ERROR: relation "..." does not exist" problem when upgrading to from rails 3.0.3 to rails 3.0.5 - it looks as though the database name pluralization algorithm had changed. What I used to have to pluralize: "project_metadatas" is now referred to as "project_metadata".

The fix for me was to add a simple migration that renamed the offending table:

class MetadataName < ActiveRecord::Migration
  def self.up
    rename_table :project_metadatas, :project_metadata
  end

  def self.down
    rename_table :project_metadata, :project_metadatas
  end
end


This looks strange:

WHERE a.attrelid = '"tags"'::regclass

The single quotes delimit a string literal, so the inner double-quotes are treated as part of the string. So it's looking for a table name that actually has " characters as part of the name.

I'm not sure how the Rails plumbing has generated that query, so I don't have anything to suggest to fix it. Sorry...

But this definitely seems to be a Leaky Abstraction problem. :-)


hi i found something so my problème was:

 `enter code here`WHERE a.attrelid = '"posts"'::regclass

are some of you using gem like rails_admin with initializer file ? because when i comment my action in my initializer file related to this model my migartion works :)

 #config.model Post do
 #  field :body, :text do
 #    ckeditor true
 #  end
 #end

So maybe (i m not sur) initializer are before rake task and. It ask for a model but there is not sql table, so bug. anyway this action work for my test and production env :)


I had the same issue, the problem was that I had forgotten to migrate the database using rake. The following got everything working correctly:

bundle exec rake db:migrate


What all gems are used by this Rails app? Do you have a .gems manifest file in the root of the app for heroku to auto detect and install? i see that you are using will paginate gem. If you haven't added the gems to the .gems file then i guess thats the trouble. If you haven't done that then this would be the best place to look for help: Heroku | Managing Gems


To add the line below to your /config/environment.rb:

ActiveRecord::Base.pluralize_table_names = false


I just discovered the source of this issue in my rails app, thanks to Bill Karwin's tip above:

When I update my db schema by running rake db:schema:dump on my dev box, it replaces some (but not all) symbols with enquoted strings...

e.g.,

add_index :taggings, ["vectors"] 

becomes

add_index "taggings", ["vectors"] 

This doesn't cause any problems on my dev box, but heroku doesn't seem to handle the discrepancy well when the db is created from scratch, but not on a db:push.

As soon as I manually switched the table names symbols, my app started playing nice again.

If anyone knows the reason for this offhand, I'd be interested...


Same problem for me but only en test and prod env.

rake db:migrate 

ok

rake db:migrate RAILS_ENV=test
rake aborted!
PGError: ERREUR:  la relation « posts » n'existe pas
LINE 4:              WHERE a.attrelid = '"posts"'::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 = '"posts"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum


I have the same problem. I bet your table name must be 'tag', not 'tags'.

If you change your table name to 'tags' in Postgresql, it will work. But why? I gave the singular model name, GHOST takes the plural.


I had the same problem after a big push even though I remembered to run migrations. For me the solution was to restart:

heroku restart
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜