<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'Chapter 10.1 - Foreign key constraints with SQLite?' | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/66/topics/419</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Casey Smith @ Tue, 13 May 2008 00:44:16 -0000</title>
      <description>&lt;p&gt;Awesome thanks Sam, I think it worked.&lt;/p&gt;</description>
      <pubDate>Tue, 13 May 2008 00:44:16 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2783</guid>
      <author>Casey Smith</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Sam Ruby @ Tue, 13 May 2008 00:07:20 -0000</title>
      <description>&lt;p&gt;Try:&lt;/p&gt;


&lt;pre&gt;
sqlite3 db/development.sqlite3 "drop table line_items;" 
rake db:migrate
&lt;/pre&gt;</description>
      <pubDate>Tue, 13 May 2008 00:07:20 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2782</guid>
      <author>Sam Ruby</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Casey Smith @ Mon, 12 May 2008 23:29:58 -0000</title>
      <description>&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;C:\rails\work\depot&amp;gt;rake db:migrate&lt;br /&gt;(in C:/rails/work/depot)&lt;br /&gt; 5 CreateOrders: migrating ================================================&lt;br /&gt;&amp;#8212;create_table(:orders)
   -&amp;gt; 0.0940s&lt;br /&gt; 5 CreateOrders: migrated (0.0940s) =======================================&lt;/p&gt;


 6 CreateLineItems: migrating =============================================&lt;br /&gt;&amp;#8212;create_table(:line_items)&lt;br /&gt;rake aborted!&lt;br /&gt;SQLite3::SQLException: table line_items already exists: &lt;span class="caps"&gt;CREATE TABLE&lt;/span&gt; line_items&lt;br /&gt;(&amp;#8220;id&amp;#8221; &lt;span class="caps"&gt;INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL&lt;/span&gt;, &amp;#8220;product_id&amp;#8221; integer &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;,
 &amp;#8220;order_id&amp;#8221; integer &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;, &amp;#8220;quantity&amp;#8221; integer &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;, &amp;#8220;total_price&amp;#8221; decimal&lt;br /&gt;(8,2) &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;, &amp;#8220;created_at&amp;#8221; datetime &lt;span class="caps"&gt;DEFAULT NULL&lt;/span&gt;, &amp;#8220;updated_at&amp;#8221; datetime &lt;span class="caps"&gt;DEFAUL&lt;/span&gt;&lt;br /&gt;&lt;span class="caps"&gt;T NULL&lt;/span&gt;)

	&lt;p&gt;File:&lt;/p&gt;


	&lt;p&gt;class CreateLineItems &amp;lt; ActiveRecord::Migration
  def self.up
    create_table :line_items do |t|
      t.integer :product_id, :null =&amp;gt; false
      t.integer :order_id, :null =&amp;gt; false
      t.integer :quantity, :null =&amp;gt; false
      t.decimal :total_price, :null =&amp;gt; false, :precision =&amp;gt; 8, :scale =&amp;gt; 2&lt;/p&gt;
	&lt;pre&gt;&lt;code&gt;t.timestamps
end&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;end
  def self.down
    drop_table :line_items
  end&lt;br /&gt;end&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Mon, 12 May 2008 23:29:58 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2781</guid>
      <author>Casey Smith</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Sam Ruby @ Mon, 12 May 2008 20:47:59 -0000</title>
      <description>&lt;p&gt;For the moment, remove the two &lt;code&gt;execute&lt;/code&gt; statements from db/migrate/006_create_line_items.rb.  I have worked out a solution for SQLite3 that I will include in the next beta.&lt;/p&gt;</description>
      <pubDate>Mon, 12 May 2008 20:47:59 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2779</guid>
      <author>Sam Ruby</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Casey Smith @ Mon, 12 May 2008 18:09:47 -0000</title>
      <description>&lt;p&gt;I have a problem when I run &amp;#8220;rake db:migrate&amp;#8221; after I have created and editied the models &amp;#8220;order&amp;#8221; and &amp;#8220;line_item&amp;#8221; on page 140 of Check out.  I get:&lt;/p&gt;


	&lt;p&gt;C:\rails\work\depot&amp;gt;rake db:migrate&lt;br /&gt;(in C:/rails/work/depot)&lt;br /&gt; 5 CreateOrders: migrating ================================================&lt;br /&gt;&amp;#8212;create_table(:orders)
   -&amp;gt; 0.0780s&lt;br /&gt; 5 CreateOrders: migrated (0.0780s) =======================================&lt;/p&gt;


 6 CreateLineItems: migrating =============================================&lt;br /&gt;&amp;#8212;create_table(:line_items)&lt;br /&gt;rake aborted!&lt;br /&gt;SQLite3::SQLException: table line_items already exists: &lt;span class="caps"&gt;CREATE TABLE&lt;/span&gt; line_items&lt;br /&gt;(&amp;#8220;id&amp;#8221; &lt;span class="caps"&gt;INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL&lt;/span&gt;, &amp;#8220;product_id&amp;#8221; integer &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;,
 &amp;#8220;order_id&amp;#8221; integer &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;, &amp;#8220;quantity&amp;#8221; integer &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;, &amp;#8220;total_price&amp;#8221; decimal&lt;br /&gt;(8,2) &lt;span class="caps"&gt;NOT NULL&lt;/span&gt;, &amp;#8220;created_at&amp;#8221; datetime &lt;span class="caps"&gt;DEFAULT NULL&lt;/span&gt;, &amp;#8220;updated_at&amp;#8221; datetime &lt;span class="caps"&gt;DEFAUL&lt;/span&gt;&lt;br /&gt;&lt;span class="caps"&gt;T NULL&lt;/span&gt;)

	&lt;p&gt;(See full trace by running task with&amp;#8212;trace)&lt;/p&gt;


	&lt;p&gt;Thanks for the help.&lt;/p&gt;</description>
      <pubDate>Mon, 12 May 2008 18:09:47 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2777</guid>
      <author>Casey Smith</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Arthur Blair @ Fri, 09 May 2008 16:56:33 -0000</title>
      <description>&lt;p&gt;Indeed, the process of looking up foreign keys in sqlite myself scared me sufficiently to give up and ask here instead.  I&amp;#8217;ll see if I can get it to work myself, and look forward to the next beta.&lt;/p&gt;


	&lt;p&gt;Thanks for your rapid response.&lt;/p&gt;</description>
      <pubDate>Fri, 09 May 2008 16:56:33 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2769</guid>
      <author>Arthur Blair</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Sam Ruby @ Fri, 09 May 2008 16:21:17 -0000</title>
      <description>&lt;p&gt;My apologies, I&amp;#8217;ll make sure that that will be fixed in the next beta.&lt;/p&gt;


	&lt;p&gt;Foreign keys are a &lt;a href="http://www.justatheory.com/computers/databases/sqlite/foreign_key_triggers.html"&gt;bit more involved&lt;/a&gt; with sqlite3.  I&amp;#8217;m thinking of deferring this to late in chapter 16.&lt;/p&gt;</description>
      <pubDate>Fri, 09 May 2008 16:21:17 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2764</guid>
      <author>Sam Ruby</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
    <item>
      <title>Chapter 10.1 - Foreign key constraints with SQLite? posted by Arthur Blair @ Fri, 09 May 2008 16:03:08 -0000</title>
      <description>&lt;p&gt;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:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
...
-- create_table(:line_items)
   -&amp;gt; 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)
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Is there an alternative syntax that will work with SQLite? (Or have I done something wrong?)&lt;/p&gt;</description>
      <pubDate>Fri, 09 May 2008 16:03:08 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:66:419:2762</guid>
      <author>Arthur Blair</author>
      <link>http://forums.pragprog.com/forums/66/topics/419</link>
    </item>
  </channel>
</rss>
