ruby on rails - PG::UndefinedColumn: ERROR: column comments.post_id does not exist -


i cant seem figure out why keep getting error. trying add comment forms blog making , wont work. here full error says.

activerecord::statementinvalid in posts#show

showing /users/ipbyrne/firstrailsapp/blog/app/views/posts/show.html.erb line #17 raised:

pg::undefinedcolumn: error: column comments.post_id not exist line 1: select count() "comments" "comments"."post_id" ... ^ : select count() "comments" "comments"."post_id" = $1

</p>     <div id="comments">        <h2><%= @post.comments.count %> comments</h2> <-- says breaks here        <%= render @post.comments %>         <h3>add comment:</h3> 

from can understand there column missing in 1 of tables in schema.rb file? incase case here mine looks like

# encoding: utf-8 # file auto-generated current state of database. instead # of editing file, please use migrations feature of active record # incrementally modify database, , regenerate schema definition. # # note schema.rb definition authoritative source # database schema. if need create application database on # system, should using db:schema:load, not running migrations # scratch. latter flawed , unsustainable approach (the more migrations # you'll amass, slower it'll run , greater likelihood issues). # # it's recommended check file version control system.  activerecord::schema.define(version: 20140911230918)    create_table "comments", force: true |t|     t.string   "name"     t.text     "body"     t.integer  "post_id"     t.datetime "created_at"     t.datetime "updated_at"   end    add_index "comments", ["post_id"], name: "index_comments_on_post_id"    create_table "posts", force: true |t|     t.string   "title"     t.text     "body"     t.datetime "created_at"     t.datetime "updated_at"   end    create_table "users", force: true |t|     t.string   "email",                  default: "", null: false     t.string   "encrypted_password",     default: "", null: false     t.string   "reset_password_token"     t.datetime "reset_password_sent_at"     t.datetime "remember_created_at"     t.integer  "sign_in_count",          default: 0,  null: false     t.datetime "current_sign_in_at"     t.datetime "last_sign_in_at"     t.string   "current_sign_in_ip"     t.string   "last_sign_in_ip"     t.datetime "created_at"     t.datetime "updated_at"   end    add_index "users", ["email"], name: "index_users_on_email", unique: true   add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true  end 

yes, you're missing field post_id on comment model, tell rails comments belong posts.

you can add generating migration command line so:

rails generate migration addpostidtocomments post:references rake db:migrate 

Comments

  1. This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post.!
    fake ids

    ReplyDelete
  2. You have done a great job. I will definitely dig it and personally recommend to my friends. I am confident they will be benefited from this site.
    pg online

    ReplyDelete
  3. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!
    แทงบอลเต็ง

    ReplyDelete
  4. So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.
    แทงบอลสเต็ป

    ReplyDelete
  5. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!
    รีวิวเว็บพนัน

    ReplyDelete
  6. I went over this website and I believe you have a lot of wonderful information, saved to my bookmarks
    รีวิวเว็บพนัน

    ReplyDelete
  7. I must say, I thought this was a pretty interesting read when it comes to thisC topic. Liked the material. . .
    ufa365

    ReplyDelete
  8. Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
    เว็บแทงบอลฝากถอนauto

    ReplyDelete
  9. You have raised an important issue..Thanks for sharing..I would like to read more current affairs from this blog..keep posting.. เว็บแทงบอลสเต็ปไม่มีขั้นต่ำ

    ReplyDelete
  10. I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job!
    UFA365

    ReplyDelete
  11. You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this.
    ทำไมต้องเล่นบาคาร่า

    ReplyDelete
  12. So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.
    แทงบาสเว็บไหนดี

    ReplyDelete
  13. Internet search engine optimization experts apply the modern analytics service, which has a positive affect a website. SEO companies are facing great competition in the SEO field. However, they introduce guaranteed SEO services to manage with the competition.

    บาคาร่าsa-gaming

    ReplyDelete
  14. his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.
    แทงบาสออนไลน์

    ReplyDelete
  15. his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.
    คาสิโนออนไลน์ฟรีโบนัส/

    ReplyDelete
  16. Whether you are involved in affiliate marketing, selling items through ClickBank, or promoting your own personal business and website, ads are an important part of one's success. Some people make a recurring income simply by placing advertisements on the websites that get a lot of traffic.
    lucky-god

    ReplyDelete
  17. It turns out that even the hottest port has a few places where you can get off the beaten path. Here are some recommendations that will make you feel like you're in the know
    สล็อตออนไลน์ufabet

    ReplyDelete
  18. Yes, great US Military force. Also, in his post you have given a chance to listen about US Military. I really appreciate your work. Thanks for sharing it.
    สล็อตออนไลน์

    ReplyDelete
  19. I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .
    ufabet

    ReplyDelete

Post a Comment

Popular posts from this blog

c# - Store DBContext Log in other EF table -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -