gpt4 book ai didi

ruby-on-rails - Heroku 推送问题第 2 部分 - Postgresql - PGError 关系不存在 - Ruby on Rails

转载 作者:数据小太阳 更新时间:2023-10-29 07:54:29 24 4
gpt4 key购买 nike

好吧,关于 Postgresql 和 SQLite 之间的区别的最后一个问题已经解决了,似乎 Heroku 告诉我我还有另一个问题。我是 ruby​​ 和 rails 的新手,所以很多东西一开始我都看不懂。在这里寻找一点方向。错误消息和 PostsController 索引如下。我检查了我的 routes.rb 文件,一切看起来都很好,但我可能遗漏了一些东西。如果你需要,我会发布。

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

最佳答案

从 rails 3.0.3 升级到 rails 3.0.5 时,我遇到了类似的“PGError: ERROR: relation “...” does not exist”问题——看起来数据库名称复数算法已经改变.我以前必须复数的内容:“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

关于ruby-on-rails - Heroku 推送问题第 2 部分 - Postgresql - PGError 关系不存在 - Ruby on Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2702353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com