SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simply Rails 2 - Stuck Pag 258 Users db

    Hello everyone.
    I've been working on this book, and it's great.
    But now i've been stuck on this for a couple of days now.
    I've checked and I made the Users db as expected.

    But in the console when I write Users I get:
    Code:
    => User(id: integer, created_at: datetime, updated_at: datetime)
    If I try to migrate again I get :
    Code:
    mbp:shovell victormartins$ rake db:migrate
    (in /Users/victormartins/Dropbox/shovell)
    ==  CreateUsers: migrating ====================================================
    -- create_table(:users)
    rake aborted!
    An error has occurred, this and all later migrations canceled:
    
    SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "login" varchar(255), "password" varchar(255), "name" varchar(255), "email" varchar(255), "created_at" datetime, "updated_at" datetime)
    So the table exists and has the necessary Users fields ( login, password, etc )

    My migrate file looks like this:

    Code:
    class CreateUsers < ActiveRecord::Migration
      def self.up
        create_table :users do |t|
          t.string :login
          t.string :password
          t.string :name
          t.string :email
    
          t.timestamps
        end
        add_column :stories, :user_id, :integer
        add_column :votes, :user_id, :integer
        
      end
    
      def self.down
        drop_table :users
        remove_column :stories, :user_id, :integer
        remove_column :votes, :user_id, :integer
        
      end
    end

    What can I do to get the Users object to see the tables on the db so I can start creating users?

    Thanks in advance.
    Victor.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,150
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Hi victormartins, welcome to the forums,
    You can create the table again by using "force" in the migration file, but it will wipe out existing data.
    Why are you trying to migrate again? What errors do you get in the console when you try to create a user?

  3. #3
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thank you, that did the trick. The data was gone but it was ok, i've inserted some more.

    I don't know what happened. I wasn't getting any error, but the User only had this fields:

    User(id: integer, created_at: datetime, updated_at: datetime)

    After the force, everything was ok.

    Thanks once again.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,150
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Make sure you take the force out or it will do the same next migration. Most likely at that point you won't want to re-enter data!

  5. #5
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to help in another time,
    is there a way to save the data of the DB and reloaded it again after a force?


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
  •