Forum: Ruby on Rails SQLite primary key schema

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C0e0b0489d676615d8e7122018baf483?d=identicon&s=25 Daniel Hackney (Guest)
on 2005-12-25 18:03
(Received via mailing list)
So after successfully getting the test SQLite db to run from memory, I
tried running some tests but found that somewhere in the schema
translation from Postgres (my devel database) and SQLite Rails fails
to properly set the 'id' column, which breaks all kinds of things.

Take as an example my 'users' table. In Postgres the schema is
(generated with pgAdmin III):
CREATE TABLE users
(
  id serial NOT NULL,
  login varchar(80),
  "password" varchar(255),
  created_on timestamp,
  updated_on timestamp,
  avatar varchar(255),
  CONSTRAINT users_pkey PRIMARY KEY (id)
)
WITH OIDS;
ALTER TABLE users OWNER TO george;

Everything works just dandy until we cross over to the SQLite world:
CREATE TABLE users (
    id serial NOT NULL,
    login character varying(80),
    "password" character varying(255),
    created_on timestamp without time zone,
    updated_on timestamp without time zone,
    avatar character varying(255)
);

That 'id serial NOT NULL' should clearly be an 'id INTEGER PRIMARY KEY
NOT NULL', but regardless of how much I play with the settings in
'sqlite_adapter.rb' and 'postgres_adapter.rb', I still get the same
result. Does anyone have any brilliant ideas?

Thanks in advance,
Dan
5b9fe87ec1faa67a4599782930f45ec9?d=identicon&s=25 Sam Stephenson (Guest)
on 2005-12-25 19:19
(Received via mailing list)
Hi,

On 12/25/05, Daniel Hackney <chrono325@gmail.com> wrote:
>   login varchar(80),
> CREATE TABLE users (
> 'sqlite_adapter.rb' and 'postgres_adapter.rb', I still get the same
> result. Does anyone have any brilliant ideas?

How is the schema being loaded into the SQLite database? Do you have
"config.active_record.schema_format = :ruby" set in
config/environment.rb (and a schema.rb in db/)?  Please show the exact
steps you're using to run your tests.

--
sam
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2005-12-25 21:13
(Received via mailing list)
On Dec 25, 2005, at 19:19, Sam Stephenson wrote:

> On 12/25/05, Daniel Hackney <chrono325@gmail.com> wrote:
>> So after successfully getting the test SQLite db to run from memory

Were you using the parameters you sent to the other thread (which
didn't actually give an in-memory database)? Or did you really
accomplish it?

I didn't succeed at all by now. Should I touch something in config/
environment.rb? I have everything as rails generates (1.0).

-- fxn
C0e0b0489d676615d8e7122018baf483?d=identicon&s=25 Daniel Hackney (Guest)
on 2005-12-25 23:28
(Received via mailing list)
Well then, it seems it was a simple problem of not RTFMing. Setting
"config.active_record.schema_format = :ruby" took care of it. It makes
sense now that it was using the same SQL schema as the devel database
by default. Thank you very much to Sam Stephenson for pointing that
out.

It seems that I still have a bit of work before getting the in-memory
SQLite database to work (using ":memory" does not give errors because
it just uses the file :memory). So that is still a mystery. I got the
sqlite schema dump by changing dbfile to db/test.db and then just
dumping its schema like normal.

Thanks again for the help,
Daniel Hackney
This topic is locked and can not be replied to.