Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord::UnknownAttributeError (unknown attribute: authorname):

I am having a some trouble on my heroku-server. Not getting this problem locally:

2014-07-23T16:59:23.249055+00:00 app[web.1]: ActiveRecord::UnknownAttributeError (unknown attribute: authorname):
2014-07-23T16:59:23.249058+00:00 app[web.1]:   app/controllers/chapters_controller.rb:5:in `create'

My controller:

class ChaptersController < ApplicationController

    def create
        @story = Story.find(params[:story_id])
        @chapter = @story.chapters.create(chapter_params)
        redirect_to story_path(@story)
    end

    def destroy
        @story = Story.find(params[:story_id])
        @chapter = @story.chapters.find(params[:id])
        @chapter.destroy
        redirect_to story_path(@story)
    end

    def upvote
        @chapter = Chapter.find(params[:id])
        @chapter.votes.create
        redirect_to(:back)
    end

    private
        def chapter_params
            params.require(:chapter).permit(:round, :author, :authorname, :body)
        end
end

I have just added authorname with

rails g migration add_authorname_to_chapter authorname:string

What am I missing?

Edit, adding schema info: ActiveRecord::Schema.define(version: 20140723154333) do

  create_table "chapters", force: true do |t|
    t.string   "round"
    t.string   "author"
    t.text     "body"
    t.integer  "story_id"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "authorname"
  end
like image 905
yarism Avatar asked Mar 18 '23 23:03

yarism


2 Answers

Restarting your server after migration will refresh the schema cache.

like image 54
Paul Tyng Avatar answered Apr 07 '23 07:04

Paul Tyng


For the case that a restart doesn't work I was able to resolve this issue by also dumping the schema:

heroku run rake db:schema:dump
heroku restart
like image 35
agbodike Avatar answered Apr 07 '23 05:04

agbodike