Simply Rails 2 Mistake: Unable to open database file

Posted by on August 27, 2008

In Chapter 4 of Sitepoint’s Simply Rails 2, you are told to run the command

sqlite3 db/development.sqlite3

then execute the sql query

CREATE TABLE `stories` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`link` varchar(255) default NULL,
PRIMARY KEY (`id`)
);

Unfortunately, following these directions you get the error: Unable to open database "db/development.sqlite3": unable to open database file.

After searching a sitepoint post I found that you have to run rake db:migrate first in the command line from the shovell directory project first, and then run this SQL query instead:

CREATE TABLE `stories` (
`id` int(11) autoincrement NOT NULL,
`name` varchar(255) default NULL,
`link` varchar(255) default NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL
,
PRIMARY KEY (`id`)
);

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. mdgrech Dec 13, 2008 00:46

    Wow good call…didnt think I would find an answer to this prob so fast.

  2. Yas Feb 15, 2009 20:03

    Thanks for the info so much. I was stuck on the page in SimplyRails2.

  3. MrTommm Nov 06, 2009 10:34

    With SQLite V 3.5.6, the table creation syntax is:

    CREATE TABLE “stories” (
    “id” int(11) NOT NULL,
    “name” varchar(255) default NULL,
    “link” varchar(255) default NULL,
    “created_at” datetime DEFAULT NULL,
    “updated_at” datetime DEFAULT NULL,
    PRIMARY KEY (“id”)
    );

    The PRIMARY KEY (“id”) automatically makes it autoincrement

Comments

Comments: