I'm working through the Rails intro on
http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html, and having a
bit of a problem with the part on page three, where you add a recipe
to the database. My recipes table (in Postgresql) looks like this:
Column | Type | Modifiers
id | integer | not null
title | character varying(255) | not null
description | character varying(255) |
date | date |
instructions | text |
"recipes_pkey" PRIMARY KEY, btree (id)
When I go to add an entry using the Rails structure, I get the following error:
ActiveRecord::StatementInvalid in Recipe#create
ERROR: null value in column "id" violates not-null constraint
: INSERT INTO recipes ("title", "date", "description", "instructions") VALUES('Cookies',
'2005-08-22', 'Good Stuff', 'I like cookeis a lot.
Mix the ingredient, and cook them.
So, it's looking like Rails isn't properly handling the primary key
constraint on the table. Is rails supposed to do this, or should I
ditch the primary key in the database? I don't know much about
databases or about rails, so I'm probably missing something really
obvious. Any ideas?