2017-06-12 123 views
1

heroku run rails db:migrate後,我得到這個錯誤的堆棧跟蹤其中包括:Heroku的運行軌道分貝:遷移

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "categories" does not exist: CREATE TABLE "products" ("id" serial primary key, "title" character varying, "description" character varying, "category_id" integer, "picture" character varying, "video" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_fb915499a4"

FOREIGN KEY ("category_id") REFERENCES "categories" ("id"))

然後我跑heroku run:detached rake db:migrate和它的工作。

但是,當我去到現場的網址,我得到這個錯誤:

ActiveRecord::StatementInvalid in WelcomeController#index

PG::UndefinedTable: ERROR: relation "products" does not exist LINE 1: SELECT "products".* FROM "products" ORDER BY "products"."cr...^: SELECT "products".* FROM "products" ORDER BY "products"."created_at" ASC LIMIT $1

編輯:

class WelcomeController < ApplicationController 
    def index 
    end 
end 

而且錯誤指向該行:

@all_products = Product.order(created_at: :asc).last(4) 

定義在application_controller.rb像這樣:

def getProducts 
    @all_products = Product.order(created_at: :asc).last(4) 
end 

welcome/index.html.erb中使用了@all_products變量來顯示最近4次上傳的產品。

它被稱爲像這樣:

<div class="text-center"> 
<% if @all_products.present? %> 
    <% @all_products.each do |p| %> 
    <a href="<%= p.picture() %>" data-toggle="lightbox" data-gallery="example-gallery" data-title="<%= p.title %>"> 
     <%= image_tag(p.picture.url, size: '200x200', class: 'rounded') %> 
    </a>&nbsp;&nbsp;  
    <% end %> 
<% end %> 
</div> 
+0

看到上面的更新 – JohnnyDevv

+0

上面的另一個更新 – JohnnyDevv

+0

你有在數據庫中的記錄? –

回答

0

一個rake db:migrate運行在一個一次性的過程,你的web程序將已經啓動並緩存原來的DB模式,您需要重新啓動您的應用程序遷移以下正在運行以重新緩存新的模式。

+0

然後我推到heroku對不對? – JohnnyDevv

+0

它的工作原理!最後 – JohnnyDevv

+0

你一定是個野獸 – JohnnyDevv

相關問題