2010-04-23 49 views
3

好吧,通过Postgresql和SQLite之间的差异来解决最后一个问题,好像Heroku告诉我我有另一个问题。我对Ruby和Rails很陌生,所以我开始无法解读这些东西。在这里寻找一个小方向。错误消息和PostsController索引如下。我检查了我的routes.rb文件,并且在那里似乎都很好,但我可能会错过一些东西。如果您需要,我会发布。Heroku推问题第2部分 - Postgresql - PGError关系不存在 - Ruby on Rails

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#指数

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 
+0

你试过“heroku rake db:migrate”吗? – 2010-08-13 13:25:53

+0

@Comptrol“heroku rake db:migrate”为我做了诡计。 Cmd行输出表示该cmd已被弃用,而应该使用“heroku run rake”。那么这是否意味着每次我通过运行“git push heroku master”后的迁移在本地进行db更改时,我都必须跟进一个“heroku run rake”? – 2013-03-25 18:51:52

回答

0

这个Rails应用程序使用了哪些所有宝石?你在应用程序的根目录下有一个.gems清单文件,用于自动检测和安装?我看到你正在使用分页宝石。如果你没有添加宝石到.gems文件,那么我想这就是麻烦。如果你没有这样做,那么这将是寻求帮助最好的地方:Heroku | Managing Gems

+0

我正在使用will_paginate,回形针,wysihat引擎。他们都在environment.rb文件中有行。是不是heroku看起来自动安装这个东西的environment.rb文件? – bgadoci 2010-04-24 19:55:54

+0

糟糕! Heroku不会自动从environment.rb文件中检测到。您的应用程序根目录中需要一个特殊的.gems清单文件。创建一个,并添加所有的宝石。该程序在上面的链接中描述。我想你所有与heroku有关的问题都解决了。 :) – 2010-04-25 02:07:14

+0

以及为什么这个问题有关?其他人回答的地址更好! – Mauricio 2010-12-10 14:55:23

1

这看起来很奇怪:

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

单引号分隔字符串文字,所以内双引号都被视为字符串的一部分。所以它正在寻找一个名称实际上包含"字符的表名。

我不确定Rails管道如何生成该查询,所以我没有任何建议来解决它。对不起...

但是,这绝对好像是一个Leaky Abstraction的问题。 :-)

+0

这并不是很让人安慰。不真正了解您提供的链接中的所有内容。我确定没有一个表格“,因为我甚至不认为这是可能的,希望以前有人看到过这个。我对ruby,rails和编程一般都很陌生,所以这对于 – bgadoci 2010-04-24 03:50:34

+1

通常Rails会从你的ActiveRecord类名中推断出这个表的名字,但是这个名字可以被覆盖,也许你在某处指定了SQL表名,并且意外地包含了“字符? – 2010-04-24 04:35:44

0

我刚刚发现这个问题的根源在我的Rails应用程序,以上感谢比尔Karwin的提示:

当我通过运行耙分贝更新我的DB模式:架构:甩在我的dev的盒子,它取代了一些(但不是全部)与enquoted串符号...

例如,

add_index :taggings, ["vectors"] 

成为

add_index "taggings", ["vectors"] 

这并不会导致我的开发盒上出现任何问题,但是当数据库是从头开始创建而不是在db:push上时,heroku似乎无法很好地处理差异。

只要我手动切换表名称符号,我的应用程序开始再次打好。

如果有人知道这个副手的原因,我有兴趣......

0

我有同样的问题。我敢打赌,你的表名必须是'tag',而不是'tags'。

如果您在Postgresql中将表名更改为'tags',它将起作用。但为什么?我给出了单数型号名称,GHOST取复数。

0

要添加线以下到您/config/environment.rb

ActiveRecord::Base.pluralize_table_names = false 
2

我也陷入了类似“PGError:ERROR:关系” ......从轨3.0升级到时“不存在”的问题。3到rails 3.0.5 - 看起来好像数据库名称复数化算法已经改变。我曾经需要复数:“project_metadatas”现在被称为“project_metadata”。

我此修复程序是添加一个简单的迁移是改名违规表:

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 
0

同样的问题对我来说,但只有连接测试和生产线ENV。

rake db:migrate 

确定

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 
1

喜 我发现了一些 所以我problème是:

有些用户在使用宝石像初始化文件rails_admin是谁? 因为当我的评论我的行动,我的初始化文件,与此相关的模型我migartion工程:)

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

所以也许(我不是SUR)的初始化是rake任务之前。它要求一个模型,但 不是sql表,所以错误。 无论如何这个行动为我的测试和生产环境:)工作

1

我有同样的问题,问题是我忘记迁移数据库使用耙子。下面的一切工作正常:

bundle exec rake db:migrate 
0

即使我记得运行迁移时,我有一个大推后同样的问题。对我来说,解决方案是重新启动:

heroku restart