在stackoverflow中有相当多的这些问题,其中没有一个能够帮助我。我使用rails和postgresql启动amazon ec2。我把它推出,但不断收到以下错误(我所做的一切,包括耙分贝:这里迁移,即使一切https://stackoverflow.com/a/19804714/7039895):PG :: UndefinedTable:错误:关系“”不存在 - Amazon EC2,Postgresql和Rails 5
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "campaigns" does not exist
LINE 8: WHERE a.attrelid = '"campaigns"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
(SELECT c.collname FROM pg_collation c, pg_type t
WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation),
col_description(a.attrelid, a.attnum) AS comment
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"campaigns"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
):
app/models/campaign.rb:15:in `block in <class:Campaign>'
app/controllers/creatives_controller.rb:30:in `storage'
app/controllers/creatives_controller.rb:5:in `index'
下面是从应用程序跟踪文件:
campaign.rb(模型)
class Campaign < ApplicationRecord
acts_as_taggable # Alias for acts_as_taggable_on :tags
extend FriendlyId
friendly_id :title, use: :slugged
belongs_to :author
has_attached_file :image, styles: { large: "600X600", medium: "300x300>", thumb: "150x150#" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
PER_PAGE = 3
scope :most_recent, -> {order(published_at: :desc)}
scope :published, -> { where(published: true) }
scope :recent_paginated, -> (page) { most_recent.paginate(page: page, per_page: PER_PAGE) }
scope :with_tag, -> (tag) { tagged_with(tag) if tag.present? }
scope :list_for, -> (page, tag) do
recent_paginated(page).with_tag(tag)
end
def display_day_published
if published_at.present?
"Published #{published_at.strftime('%-b %-d, %Y')}"
else
"Not published yet."
end
end
def publish
update(published: true, published_at: Time.now)
end
def unpublish
update(published: false, published_at: nil)
end
end
creatives_controller.rb(同时具有索引和存储)
class CreativesController < ApplicationController
layout "creative"
def index
@campaigns = storage.list_for(params[:page], params[:tag])
@campaigned = Campaign.order("created_at DESC").limit(6)
@recent = Campaign.order("created_at DESC").limit(3)
end
# GET /posts/1
# GET /posts/1.json
def show
@campaign = storage.friendly.find(params[:id])
@gallery = storage.friendly.find(params[:id])
end
def gallery
@galleries = storage.list_for(params[:page], params[:tag])
@galleried = Gallery.order("created_at DESC")
@current = Gallery.order("created_at DESC")
end
private
def storage
Campaign.published
Gallery.published
end
end
当我在本地运行它时,它工作正常。当我在我的amazon ec2实例中运行它时,它一直给我这个错误。任何帮助将不胜感激。
而且,这里是在index.html.erb文件中的代码:
<!-- Portfolio Box -->
<ul class="list-unstyled row portfolio-box">
<% @recent.each do |campaign| %>
<li class="col-sm-4">
<%= link_to campaign.image.url, :class => "thumbnail fancybox", data: { rel: "gallery" }, title: campaign.title do %>
<%= image_tag campaign.image, :class => "full-width img-responsive" %>
<span class="rounded-x portfolio-box-in">
<i class="fa fa-search-plus"></i>
</span>
<% end %>
<div class="headline-left margin-bottom-10"><h3 class="headline-brd"><%= campaign.title %></h3></div>
<small class="project-tag"><i class="fa fa-tags"></i><%= raw campaign.tags.map{ |t| link_to t.name, campaigns_path(tag: t.name)}.join(', ') %></small>
<p><%= truncate(campaign.description, length: 130) %> </p>
</li>
<%end%>
</ul>
<!-- End Portfolio Box -->
SQL是ActiveRecord用来确定“campaign”表的结构的。该错误告诉你AR所连接的数据库没有“campaign”表。大概你错过了一个会创建该表的迁移,或者你连接到了错误的数据库。 –
当我检查我的数据库时,它显示它在那里。 –
您是否通过连接Rails所用的相同凭据来检查该问题,并且您可以从表中选择? –