SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 33

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation SQLite Problem in Simply Rails 2

    Hi All,

    I just started with Simply Rails 2 ebook and am stuck on page 102,Shmay, not sure if my problem was related, but I tried to paste the code on page 102 into the sqlite console (while I am in the "app" directory:

    CREATE TABLE stories (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    "name" varchar(255) DEFAULT NULL,
    "link" varchar(255) DEFAULT NULL,
    "created_at" datetime DEFAULT NULL,
    "updated_at" datetime DEFAULT NULL
    );



    and, I get the message:

    Unable to open database "db/development.sqlite3": unable to open database file

    I'm not sure if it is because I am in the wrong folder when I execute the command? I usually move into the "app" directory to do this. I think that the installation went all right, because it gives the version number when i check, and when i enter: "sqlite3 db/development.sqlite3"

    I get the following:
    SQLite version 3.5.4
    Enter ".help" for instructions
    sqlite>

    If anyone else is reading this, please let me know what i'm doing wrong!!

    Thanks so much!!
    D

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do it this way, from your rails project root (one directory up from app):

    rake db:create
    If that worked, we are in business.

    ruby script/generate scaffold name:string link:string
    Hey look at those files that were created.

    rake db:migrate
    This will change the schema.

    That almost certainly doesn't mesh with the book, but it should work and maybe give you a sense of what does what. You can make a clean project and try it if you don't want to taint your book work:

    rails what_some_internet_person_suggested
    stuff I suggested
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sam
    Thanks so much for your quick reply!! I tried what you suggested. I went to the project root (which is "Shovell" in this case, same as the book) and then I did what you mentioned with the following responses:

    a.) rake db:create
    <b>(in /Users/soobeng/Desktop/build/shovell)
    "db/development.sqlite3 already exists"</b>

    b.) ruby script/generate scaffold name:string link:string
    <b>wrong constant name Name:stringsController</b>

    Not sure what I should do next. From the error messages, could it be that I missed some step in installing SQLite? It seems not to me because it could give me the version number.

    THanks again
    D

  4. #4
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first error is all good, means things probably work including sqlite.

    The second error was my bad.

    ruby script/generate scaffold story name:string link:string

    I left out "story".

    It is saying something like ...
    Generate a scaffold for "story", which has name and link varchar columns.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  5. #5
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sam
    I'm such a cumba**!! I had been trying to run the table creation process while i was in the "app" directory. I changed the directory to the "shovell" directory and it works now. Thanks so much for your help!!
    Was panicking when I thought I would not even make it through the database set up stage.....
    Thanks again
    D.

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Reigate and Bath, UK.
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    please could you help me too?

    i was doing ok up until page 102- the sqlite3 db/development.sqlite3 command seems to work, but everything i try, including your code, that in the book and that included in the code archive, doesn't seem to get me anywhere.

    below is what my terminal window reads, in the hope you can clear up where i'm going wrong!

    Last login: Wed Jun 18 15:54:04 on ttys000
    You have mail.
    Macintosh-9:~ Laura$ cd shovell
    Macintosh-9:shovell Laura$ sqlite3 db/development.sqlite3
    SQLite version 3.4.0
    Enter ".help" for instructions
    sqlite> USE shovell_development;
    SQL error: near "USE": syntax error
    sqlite> CREATE TABLE `stories` (
    ...> `id` int(11) NOT NULL auto_increment,
    ...> `name` varchar(255) default NULL,
    ...> `link` varchar(255) default NULL,
    ...> PRIMARY KEY (`id`)
    ...> );
    SQL error: near "auto_increment": syntax error
    sqlite> rake db:create
    ...> ruby script/generate scaffold name:string link:string
    ...> rake db:migrate
    ...>

  7. #7
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Laura K View Post
    Macintosh-9:shovell Laura$ sqlite3 db/development.sqlite3
    sqlite> USE shovell_development;
    Don't do that.

    Just do this (from the command line, not in SQLite):
    Quote Originally Posted by Laura K View Post
    rake db:create
    ruby script/generate scaffold story name:string link:string
    rake db:migrate
    Last edited by samsm; Jun 18, 2008 at 18:12. Reason: typo!!!!
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Reigate and Bath, UK.
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks!

    that seemed to work well but upon putting in the code further on in the book, it errors that I haven't got a 'stories' table.

    so for now, I've reverted back to Agile Web Development with Rails. Hopefully between these 2 books I'll get it right!

  9. #9
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am having the same problem and there is more that adds to the confusion to this problem. If you download the sample code from the book and past it in the console the code is different as shown below:

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

    The code in the book and this sample code for the book returns the same error. Although, the code provided above is a great fix it is not a work around to accompany this book for and from Sitepoint. I was doing so well and its a great read but when you fork over $40 bucks you tend to want to use the book without having to find resources across the net. Has anyone who has this book found a way to solve this problem. I have sent the author an email so I hope I get an answer. If I do I will post any fixes the author has provided to me.

  10. #10
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Reigate and Bath, UK.
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Quote Originally Posted by C_Programmer0101 View Post
    If you download the sample code from the book and past it in the console the code is different
    I noticed that! But I thought it was down to my own incompetence!

    I'm really struggling with this, I got into difficulties using Agile Web Development With Rails as well. Just at the same point where you start doing actual rails stuff it just seems to make assumptions about what you know, in both books.

    I found all the Ruby info in Simply Rails 2 really enlightening though, started making the little ActionScript I know make more sense too!

  11. #11
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made the same typo twice in the same thread. To my credit, the second time I was copy/pasting.

    ruby script/generate scaffold story name:string link:string
    (Left out "story")

    Really, if you want to use Rails, think about never directly touching the database again. Shy away from tutorials that directly use SQL outside of migrations (unless as an example), that's a red flag.

    What happens instead is you generate a migration ...
    (script/generate migration, scaffold, model)

    ... edit the file just created in db/migrations ...

    ... then apply it with:
    rake db:migrate

    Sound convoluted? It is actually super-awesome:
    http://media.rubyonrails.org/video/migrations.mov (movie)
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  12. #12
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi i can totally sympathise with you guys!! I bought both Simply Rails and Agile ebooks and tried to finish one after the other, but found that the learning curve just shot through the roof for both so I found myself alternating between both at various stages.

    At the moment, I love Rails for its simplicity and elegance esp since I am not from a web programming background (compared to php which requires you to learn sql separately).

    Anyhow.... I have had to spend heaps esp in USD (I'm from Asia) just to learn... ah well.

  13. #13
    SitePoint Zealot daveporter's Avatar
    Join Date
    Mar 2002
    Location
    Perth, Western Australia
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page 102 SQL needs correcting...

    Hi All,

    The SQL on this page from the book looks like this:

    CREATE TABLE `stories` (
    `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    `name` varchar(255) DEFAULT NULL,
    `link` varchar(255) DEFAULT NULL,
    'created_at' datetime DEFAULT NULL,
    'updated_at' datetime DEFAULT NULL
    );

    The one from the download looks like this:

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

    Neither work when pasted into the sqlite3 console OR the Firefox sqlite-manager plug in...
    ( they complain about the auto_increment ! )

    After playing around the sql below seems to work in the Firefox sqlite-manager ( you don't need the USE statement as you selected the database first so that is a given !
    ( you probably need to do a rake db:migrate first ( at the command line ), which will create the database for you )

    CREATE TABLE `stories` (
    `id` integer primary key autoincrement NOT NULL,
    `name` varchar(255) default NULL,
    `link` varchar(255) default NULL,
    'created_at' datetime DEFAULT NULL,
    'updated_at' datetime DEFAULT NULL
    );

    I'll wait for some SitePoint feedback, but on the surface it looks a bit shoddy !

    Also why not use the command line way of doing this as introduced in Rails 2.0 It is very slick and easy and the created_at and updated_at fields get created automatically ???

    DaveP

  14. #14
    SitePoint Zealot daveporter's Avatar
    Join Date
    Mar 2002
    Location
    Perth, Western Australia
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to rub a bit of salt into the wound....

    The sql version on the article page is different again !!!!
    http://www.sitepoint.com/article/rails-for-beginners/2

    ( It should work, it is very similar to mine ! )

    So the one book has three versions of the same small bit of sql code & it's only been out a couple of weeks !

    DaveP

  15. #15
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys I have to tell you even though this is the most frustrated I have been learning a language but I have been enjoying its capabilities. This forum is awesome too so I have to give you guys that credit. Most programming forums from my experience has people who are not as helpful as you guys in sharing the knowledge.

    Laura K if you did not get an error it is good to go. If you type .quit and it goes back into the directory then it was a success. Good Job!!!

    Thanks all for the other useful ways of creating a project. I will have to use that too in a new project to play around with my options. I think later in the Simply Rails 2 book it said he will show how to create the database using only Ruby so that is cool.

  16. #16
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sitepoint replied to my inquiry with this:

    The example SQL for 02-create-stories-table.sql des not match the code
    in the code archive, the code archive is correct. It should be:


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


    I hope this helps! Let me know if you have any further queries or
    concerns.

    I replied back that the code returns the errors but the code in the book actually worked. The two resourced conflict with each other so lets see what happens from there.

  17. #17
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Reigate and Bath, UK.
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got an auto_increment error off that. oh dear

  18. #18
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Reigate and Bath, UK.
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the next bit again, just to see if any of what I've done was ok.

    Got the following:

    >> class Story < ActiveRecord::Base
    >> end
    => nil
    >> story = Story.new
    ActiveRecord::StatementInvalid: Could not find table 'stories'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:29:in `table_structure'
    from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/object/misc.rb:28:in `returning'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:189:in `columns'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1145:in `columns'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2598:in `attributes_from_column_definition_without_lock'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/locking/optimistic.rb:55:in `attributes_from_column_definition'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2126:in `initialize'
    from (irb):3:in `new'
    from (irb):3
    >>

    Does this mean anything?

  19. #19
    SitePoint Zealot daveporter's Avatar
    Join Date
    Mar 2002
    Location
    Perth, Western Australia
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Laura,

    As you got an error with your sql statement two messages back then the next part will not work as the stories table does not exist.

    Look back on my two earlier messages in this thread that may help you.

    regards, DaveP

  20. #20
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys! When you use the second database code the author has you download it will give you the auto_increment error as you all know. I have not received a reply back from the author. I think to many errors play a part in the way the book was written. The code I show I think my problem is because I have two installs of ruby on my Mac. Others maybe having problems with a browser or operating system they are currently using. You cant tell by my tone but I am really frustrated right now because I usually will be done with a programming book by now and for the last three to four weeks I have been stuck in chapter 4. The way others suggested to set up a project works but going that route make my book worthless. I am going to go play around with it again and see if I can get it going. If I get a resolution I will let you guys know.

  21. #21
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had two paths (.profile and .bash_profile) that had ruby on rails installs. Both installs were up to date but I think there were conflicts. I added both paths for each profile and tried to go through the steps in the book again.

    Get this!!!

    I copied and pasted the coded over and over again and kept getting the same errors of class stories can not be found. So I kept on pasting over and over in the console. Next, thing you know it worked lol. Everytime I paste it in the console it works. I am now in chapter five so I have no clue on why its working except adding each path to each profile. I think this might be a bug of some sort. I was reading reviews of other books and every nOOb is having issues on these books so it leads me to believe ruby on rails might be extremely buggy. But I hope that is not the case.

  22. #22
    SitePoint Member
    Join Date
    May 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok.

  23. #23
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The database code is the smoking gun, everyone who uses Rails has used migrations for years now. Just like you don't directly write select, and update queries, you don't write create queries either. In addition to being easier, this approach insulates you from minor changes and allows you to easily switch to MySQL or whatever. If this book isn't advocating that approach, I'd get rid of it.

    If you have the stack set up, and want to burn 5 minutes, do this:
    mkdir temporary_folder
    cd temporary_folder
    rails quickapp
    cd quickapp
    ruby script/generate scaffold story name:string link:string
    rake db:migrate
    ruby script/server -p 3003
    (in browser: http://localhost:3003/stories )

    I just ran that one, so no typos.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  24. #24
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When i got to page 102 of Simply Rails 2, I had the same problem creating the 'stories' table from the code in the code archive, since I always got an auto_increment error. After playing around with the statements, I found if I changed int(11) to INTEGER for the 'id' field, it worked. But after looking at posts in this forum, I noticed that the code in the book, besides using INTEGER for the 'id', also had two other fields, so I dropped the stories table I had created and used the code from the book, which is:

    CREATE TABLE `stories` (
    `id` integer primary key autoincrement NOT NULL,
    `name` varchar(255) default NULL,
    `link` varchar(255) default NULL,
    'created_at' datetime DEFAULT NULL,
    'updated_at' datetime DEFAULT NULL
    );


    That worked without giving me an auto_increment error, so now I'm proceeding with the rest of the book. Hope that helps someone else.

  25. #25
    SitePoint Member
    Join Date
    May 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried changing to the db directory and then running sqlite3 (without the now unnecessary 'db/' part) and that seemed to work. Here's the commands I used:

    $cd db (from the shovell directory)
    $sqlite3 development.sqlite3
    sqlite> create table stories (
    ...> "id" integer primary key autoincrement not null,
    ...> "name" varchar(255) default null,
    ...> "link" varchar(255) default null,
    ...> "created_at" datetime default null,
    ...> "updated_at" datetime default null);

    (I did run a rake db:migrate command from the root directory earlier, but I'm not sure it affected anything.)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •