Make id a serial, don''t bother with creating your own sequence:
CREATE TABLE todos(
id serial NOT NULL,
description varchar(100) NOT NULL,
done boolean NOT NULL default false,
primary key(id)
);
That may not be 100% perfect (I changed your int2 to boolean), but at
least you can see how serial fields work in postgres.
On 7/29/05, Akbar <akbarhome-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I am newbie. I try to follow the todo list tutorial. The tutorial use
mysql
> database. But mysql give me headache. It told me to update the mysql by
"gem
> update mysql" but "gem update mysql" give me this error:
> Upgrading installed gems...
> Attempting remote upgrade of mysql
> Attempting remote installation of ''mysql''
> Building native extensions. This could take a while...
> ERROR: While executing gem ... (RuntimeError)
> ERROR: Failed to build gem native extension.
> Gem files will remain installed in
> /usr/lib/ruby/gems/1.8/gems/mysql-2.6 for inspection.
> ruby extconf.rb update mysql\nchecking for mysql_query() in
> -lmysqlclient... no
> checking for main() in -lm... yes
> checking for mysql_query() in -lmysqlclient... no
> checking for main() in -lz... Upgrading installed gems...
> Attempting remote upgrade of mysql
> Attempting remote installation of ''mysql''
> Building native extensions. This could take a while...
> ERROR: While executing gem ... (RuntimeError)
> ERROR: Failed to build gem native extension.
> Gem files will remain installed in
> /usr/lib/ruby/gems/1.8/gems/mysql-2.6 for inspection.
> ruby extconf.rb update mysql\nchecking for mysql_query() in
> -lmysqlclient... no
> checking for main() in -lm... yes
> checking for mysql_query() in -lmysqlclient... no
> checking for main() in -lz... yes
> checking for mysql_query() in -lmysqlclient... no
> checking for main() in -lsocket... no
> checking for mysql_query() in -lmysqlclient... no
> checking for main() in -lnsl... yes
> checking for mysql_query() in -lmysqlclient... no
>
>
> Results logged to
> /usr/lib/ruby/gems/1.8/gems/mysql-2.6/gem_make.out
> yes
> checking for mysql_query() in -lmysqlclient... no
> checking for main() in -lsocket... no
> checking for mysql_query() in -lmysqlclient... no
> checking for main() in -lnsl... yes
> checking for mysql_query() in -lmysqlclient... no
>
>
> Results logged to
> /usr/lib/ruby/gems/1.8/gems/mysql-2.6/gem_make.out
>
> I use FC4. So I change database to postgresql. The author of the tutorial
> create the table like this:
> -- Create the table
> CREATE TABLE `todos` (
> `id` INT NOT NULL AUTO_INCREMENT ,
> `description` VARCHAR( 100 ) NOT NULL ,
> `done` TINYINT DEFAULT ''0'' NOT NULL ,
> PRIMARY KEY ( `id` )
> );
> But postgresql does not have auto_increment. So I simulate it:
> CREATE SEQUENCE sequence_todo
> INCREMENT 1
> MINVALUE 1
> MAXVALUE 1000
> START 1
> CACHE 1;
> ALTER TABLE sequence_todo OWNER TO postgres;
>
> CREATE TABLE todos
> (
> description varchar(100) NOT NULL,
> done int2 NOT NULL DEFAULT 0,
> id int4 NOT NULL DEFAULT
nextval(''public.sequence_todo''::text)
> )
> WITH OIDS;
> ALTER TABLE todos OWNER TO postgres;
>
> Later when I try to create new record in rail, by clicking create button,
I
> got this error:
> ERROR C42P01 Mrelation "todos_id_seq" does not exist
Fnamespace.c L201
> RRangeVarGetRelid
>
> How do I solve this problem? Thank you.
>
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>