May 9, 2008
Generic-user-small Arthur Blair 2 posts

Topic: Agile Web Development with Rails, 3rd Edition / Chapter 10.1 - Foreign key constraints with SQLite?

Indeed, the process of looking up foreign keys in sqlite myself scared me sufficiently to give up and ask here instead. I’ll see if I can get it to work myself, and look forward to the next beta.

Thanks for your rapid response.

 
May 9, 2008
Generic-user-small Arthur Blair 2 posts

Topic: Agile Web Development with Rails, 3rd Edition / Chapter 10.1 - Foreign key constraints with SQLite?

Page 141 uses MySQL statements to specify the foreign key constraints, which associate the rows of the line_items table with orders and products. However, using SQLite (as recommended earlier in the book) these statements give a syntax error:


...
-- create_table(:line_items)
   -> 0.0090s
-- execute("alter table line_items add constraint fk_line_item_products
             foreign key (product_id) references products(id)")
rake aborted!
SQLite3::SQLException: near "constraint": syntax error: alter table line_items add constraint fk_line_item_products
                 foreign key (product_id) references products(id)

Is there an alternative syntax that will work with SQLite? (Or have I done something wrong?)

2 posts