Rails: id field is nil when calling Model.new

Posted by Joe Cannatti on Stack Overflow See other posts from Stack Overflow or by Joe Cannatti
Published on 2010-04-11T22:07:37Z Indexed on 2010/04/11 22:13 UTC
Read the original article Hit count: 171

Filed under:
|

I am a little confused about the auto-increment id field in rails. I have a rails project with a simple schema. When i check the development.sqlite3 I can see that all of my tables have an id field with auto increment.

CREATE TABLE "messages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "text" text, "created_at" datetime, "updated_at" datetime);

but when i call Message.new on the console, the resulting object has an id of nil

>> a = Message.new
=> #<Message id: nil, text: nil, created_at: nil, updated_at: nil>

shouldn't the id come back populated?

© Stack Overflow or respective owner

Related posts about rails

Related posts about activerecord