SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Table `stories already exists. Could not find table stories.

    Argh, I am trying to follow along with SitePoint's well written ruby on rails tutorial for beginners . I'm on page nine and I made the table in the database (I have no idea where the database is located or how Rails is supposed to know that it is communicating with that database and not another one.) But when I attempt to make story an object in rails using the line
    Code Ruby:
    story = Story.new
    I get this result:
    Code :
    ActiveRecord::StatementInvalid: Could not find table `stories`
    And then a bunch of jargon following. I tried to screenshot it but I'm not allowed to post links yet and I can't copy/paste.

    I'm using the Rails console. Any ideas? Thanks. :]

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Did you create the table using the SQLite console?

    The "database" location is shovell/db/development.sqlite3

    Check the shovell/config/database.yaml file to see if it looks like
    Code:
    .....
    development:
      adapter: sqlite3
      database: db/development.sqlite3
      timeout: 5000
    .....

  3. #3
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No I used mySQL command line to do it. And for some reason that file is 0 bytes. The tutorial didn't tell me to put anything there, although it did tell me to examine shovell\config\database.yml.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    SQLite is not the same as MySQL. You can use MySQL if you want to as long as you specify it in the yml file. You don't need to put anything in the database file. RoR does that for you.

  5. #5
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm kind of confused but I really appreciate your help. So I just realized that the program I was working with was just a .rb file located in a folder I called practice. I now realize that it should be located in a sub directory of "C:\cygwin\home\Owner\shovell\app". Which sub directory should it go in, controllers, models, helpers, or views? Also, what should it's name be, if it has to be something in specific? I changed the data in the yml file to say

    development:
    adapter: sqlite3
    database: db/development.sqlite3
    pool: 5
    timeout: 5000

    Since it was previously empty. I'm sorry if I'm sounding stupid this is my first day doing rails and I'm a bit confused. Thanks again for your help.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    For the few RoR projects I've worked with I've always CDed to the main folder. i.e.
    .../shovell>


    RoR creates the directory structure and puts the created files in their places for you.

    >rails shovell
    creates the directory framework

    shovell>ruby script/generate model Story name:string link:string
    creates several files in their appropriate places

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good advice from Mittineague, but I would add:

    Quote Originally Posted by fashionnugget View Post
    ...I was working with was just a .rb file located in a folder I called practice. I now realize that it should be located in a sub directory of "C:\cygwin\home\Owner\shovell\app".
    Also worth noting is that Rails application files will not work in isolation. They need to be used within the application. Your statement above seems to indicate that you are getting to the ruby console line directly (via irb?) rather than actually using the Rails console.

    To test your application at the console level the best policy is to navigate to the root of your application in the Windows shell (DOS/Command window) and then use the following command to access the Rails console:
    Code:
    ruby script/console
    That will get you to a ruby console but crucially will also load all the supporting systems needed for the application to run.

    Looking at your earlier postings, that command needs to be run at "C:\cygwin\home\Owner\shovell\app". So:
    Code:
    C:\>cd C:\cygwin\home\Owner\shovell\app
    C:\cygwin\home\Owner\shovell\app>ruby script/console

  8. #8
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But which file is the actual one that I modify?

  9. #9
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the first place to start is for you to post your database.yml. Put it between [code] and [/code] and the formatting will be preserved in your posting. From the database.yml we will be able to see how your application is configured to connect to the database. Once we know that, we can give you more specific advice as to what to do next.

  10. #10
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code Ruby:
    # SQLite version 3.x
    #   gem install sqlite3-ruby (not necessary on OS X Leopard)
    development:
      adapter: sqlite3
      database: db/development.sqlite3
      pool: 5
      timeout: 5000
     
    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
      adapter: sqlite3
      database: db/test.sqlite3
      pool: 5
      timeout: 5000
     
    production:
      adapter: sqlite3
      database: db/production.sqlite3
      pool: 5
      timeout: 5000

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Are you using a Windows OS? It seems to be rather common for Windows users to have problems with SQLite3. Although AFAIK it's usually a problem with installing the GEM, not it's operation afterwards.

    In any case, if you CD to the shovell folder and (use \ for Windows)
    Code:
    ..shovell>sqlite3 db/development.sqlite3
    Do you see something like
    Code:
    C:\ruby\shovell>sqlite3 db\development.sqlite3
    SQLite version 3.6.1
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>
    and if you enter .tables do you see something like
    Code:
    sqlite> .tables
    schema_migrations  taggings           users
    stories            tags               votes
    sqlite>
    *some tables come later on in the book


Tags for this Thread

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
  •