這個問題讓我難堪。Heroku Rails - ActiveRecord :: UnknownAttributeError(未知屬性'user_id'的時間表。):
當部署到Heroku上我得到了錯誤,但沒有在本地這將指示與DB
線的參照
class StaticPagesController < ApplicationController
def home
if logged_in?
@project = current_user.projects.build if logged_in?
**@timetable = current_user.timetables.build if logged_in?**
@feed_items = current_user.feed.paginate(page: params[:page]).reorder("project_due_date ASC")
@feed_items3 = current_user.feed3.paginate(page: params[:page], :per_page => 1)
end
end
我已經試過
Heroku run db:migrate and Heroku restart
還是個問題相同的錯誤
這可能是事實,我有模式錯了某些BU什麼時候會影響Heroku而不是本地主機?
URL = https://radiant-sea-5676.herokuapp.com/
編輯 - 這似乎在登錄狀態下,當沒有登錄在Heroku,但崩潰上班工作在本地主機上任何一種方式。
再次編輯 - 通過Heroku檢查模式顯示,即使在遷移後,用戶iD也沒有用戶iD列和索引設置。
create_table "timetables", force: :cascade do |t|
t.string "name", limit: 255
t.string "attachment", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Localhost正常工作。其實enver有一個問題,但當我檢查使用Heroku的Heroku上的Schema運行「bundle exec rake db:schema:dump && cat db/schema.rb」其缺少的add_index「時間表」,[「user_id」],名稱:「 index_timetables_on_user_id「,使用::btree ...它的項目。項目來自哪裏?它看起來它的自動生成爲沒有user_id參數的項目,但有東西添加它 – ChrisM
架構的Pastebin http://pastebin.com/1DJF69Zr。請注意,在時間表和關於外鍵的最後一行之後索引行是如何丟失的。 – ChrisM
從Heroku中刪除ClearDB應用程序,建立一個新的。將「heroku config:set DATABASE_URL =」更改爲新的ClearDB。在這之後,Heroku運行rake:遷移正確處理並插入正確的外鍵。本地Command rake db:reset似乎是解決方案,但在使用ClearDB時,該命令在Heroky上不起作用。 – ChrisM