Heroku Rails-ActiveRecord :: UnknownAttributeError(时间表的未知属性"user_id".): [英] Heroku Rails - ActiveRecord::UnknownAttributeError (unknown attribute 'user_id' for Timetable.):

查看:119
本文介绍了Heroku Rails-ActiveRecord :: UnknownAttributeError(时间表的未知属性"user_id".):的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题让我难过.

当部署到Heroku时,我得到了错误但不是本地的,这表明数据库有问题

将其引用指向

 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 

仍然是相同的错误

可能是事实,我以某种方式出错了,但是何时会影响Heroku而不是localhost?

URL = https://radiant-sea-5676.herokuapp.com/

编辑-在未登录Heroku时似乎可以工作,但在登录时会崩溃.在本地主机上都可以工作.

再次编辑-通过Heroku检查架构显示,即使迁移后,也没有User iD列,也没有为User 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

解决方案

直到有人提供更好的解释或答案之前,我要做的就是转到Heroku仪表板并删除ClearDB数据库,然后创建一个新数据库. /p>

我为应用配置了

heroku config | grep CLEARDB_DATABASE_URL

heroku config:set DATABASE_URL='mysql://adffdadf2341:adf4234@us-cdbr-east.cleardb.com/heroku_db?reconnect=true'

然后运行heroku运行rake db:migrate并使用正确的Schema(包括外键)重建数据库.

This problem has me stumped.

When deployed to Heroku i got the error but not locally which would indicate a problem with the db

Line its referring to

 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

I've tried

Heroku run db:migrate and Heroku restart 

Still same error

It may be the fact that i have the schema wrong somehow but when woud that affect Heroku but not localhost?

URL = https://radiant-sea-5676.herokuapp.com/

Edit - It seems to work when not logged in on Heroku but crashes when logged in. Works either way on localhost.

Edit Again - Checking the schema through Heroku shows there is no User iD column and no Index setup for the User iD even after a migrate.

    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

解决方案

Until someone comes with a better explanation or answer what i had to do was go to the Heroku dashboard and delete the ClearDB database, then create a new one.

I configured the app with

heroku config | grep CLEARDB_DATABASE_URL

heroku config:set DATABASE_URL='mysql://adffdadf2341:adf4234@us-cdbr-east.cleardb.com/heroku_db?reconnect=true'

Then ran heroku run rake db:migrate and it rebuilt the database with the correct Schema including foreign keys.

这篇关于Heroku Rails-ActiveRecord :: UnknownAttributeError(时间表的未知属性"user_id".):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆