Chapter 10.1 - Foreign key constraints with SQLite?
Arthur Blair
2 posts
|
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:
Is there an alternative syntax that will work with SQLite? (Or have I done something wrong?) |
Sam Ruby
36 posts
|
My apologies, I’ll make sure that that will be fixed in the next beta. Foreign keys are a bit more involved with sqlite3. I’m thinking of deferring this to late in chapter 16. |
Arthur Blair
2 posts
|
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. |
Casey Smith
3 posts
|
I have a problem when I run “rake db:migrate” after I have created and editied the models “order” and “line_item” on page 140 of Check out. I get: C:\rails\work\depot>rake db:migrate —create_table(:line_items) rake aborted! SQLite3::SQLException: table line_items already exists: CREATE TABLE line_items (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “product_id” integer NOT NULL, “order_id” integer NOT NULL, “quantity” integer NOT NULL, “total_price” decimal (8,2) NOT NULL, “created_at” datetime DEFAULT NULL, “updated_at” datetime DEFAUL T NULL) (See full trace by running task with—trace) Thanks for the help. |
Sam Ruby
36 posts
|
For the moment, remove the two |
Casey Smith
3 posts
|
Thanks Sam but I am still getting the same error message. I have given the error message again and the text from the file. I am loving Ruby and Rails. Thanks for writing the books and help us noobs out. C:\rails\work\depot>rake db:migrate —create_table(:line_items) rake aborted! SQLite3::SQLException: table line_items already exists: CREATE TABLE line_items (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “product_id” integer NOT NULL, “order_id” integer NOT NULL, “quantity” integer NOT NULL, “total_price” decimal (8,2) NOT NULL, “created_at” datetime DEFAULT NULL, “updated_at” datetime DEFAUL T NULL) File: class CreateLineItems < ActiveRecord::Migration def self.up create_table :line_items do |t| t.integer :product_id, :null => false t.integer :order_id, :null => false t.integer :quantity, :null => false t.decimal :total_price, :null => false, :precision => 8, :scale => 2
|
Sam Ruby
36 posts
|
Try: sqlite3 db/development.sqlite3 "drop table line_items;" rake db:migrate |
Casey Smith
3 posts
|
Awesome thanks Sam, I think it worked. |
8 posts, 3 voices
