probably a stupid rails question

T

tsuraan

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:

<pre>
Table "public.recipes"
Column | Type | Modifiers=20
--------------+------------------------+-----------
id | integer | not null
title | character varying(255) | not null
description | character varying(255) |=20
date | date |=20
instructions | text |=20
Indexes:
"recipes_pkey" PRIMARY KEY, btree (id)
</pre>

When I go to add an entry using the Rails structure, I get the following er=
ror:
ActiveRecord::StatementInvalid in Recipe#create

ERROR: null value in column "id" violates not-null constraint
: INSERT INTO recipes ("title", "date", "description", "instructions") VA= LUES('Cookies',=20
'2005-08-22', 'Good Stuff', 'I like cookeis a lot.
Mix the ingredient, and cook them.

yay!
')

script/server:49

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top