Tuesday, February 5, 2008

HABTM issue with Rails 2.0.2 and SQLite3

When using SQLite3 with rails you must make sure not to add an id column to your join tables (probably a good idea in any case).

The error I got when I did have an id column where something like this:

SQL logic error or missing database: INSERT INTO
podcasts_tags("podcast_id", "id", "tag_id") VALUES (3, 3, 1)


To avoid this, make sure you include :id => false when creating the join table:

create_table :podcast_tags, :id => false do |t|
t.integer :podcast_id, :null => false
t.integer :tag_id, :null => false
end

3 comments:

Anonymous said...

thanks mate, was trying to figure that out

Aaron Tinio said...

that was short and sweet, very useful. thanks

gone_cat said...

[sigh]
thanks a bunch for that tip, this was driving me nuts!