Topic: Need help please

Ok so im following Michael Hartl's tutorial for Ruby on Rails, and I'm at this point: http://ruby.railstutorial.org/chapters/ … alidations   where I just created a "Add_Email_Uniqueness_index migration" by using the command of "rails generate migration add_email_uniqueness_index" and after he did that (im following the video examples) he does a few things in the .rb file (which i did as well) and then runs "rake db:migrate". When I ran my db:migrate I get this:

lithium@ubuntu:~/blog$ rake db:migrate
==  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, "name" varchar(255), "email" varchar(255), "state" varchar(255), "city" varchar(255), "years" integer, "created_at" datetime, "updated_at" datetime)

Tasks: TOP => db:migrate
(See full trace by running task with --trace)




I don't understand what went wrong?

Last edited by _lithium_ (2011-08-14 10:28:00)

Re: Need help please

You seem to have create statement in your migration when the database already has a table by this name.  The two most likely causes that pops to my mind are:

  • your 'uniqueness' migration has a create statement in it, or

  • your schema does not reflect the database structure (a rare but possible case)

First make sure your migration is exactly the same as in the book.  If it still fails, run 'bundle exec rake db:schema:load' and then migrate your DB.  (Beware!  This will erase your database contents entirely!)

Re: Need help please

The thing that sucks is I'm following a video guide, and my stuff should be the exact same as the guys, and when i do the rake db:migrate, it gives me that error but the guy's just works with no issues. IDK what the hell im doing wrong, i tried the "bundle exec rake db:schema:load" and it just said this: (I also ran db:migrate afterwords)

lithium@ubuntu:~/blog$ bundle exec rake db:schema:load
-- create_table("comments", {:force=>true})
   -> 0.8508s
-- create_table("posts", {:force=>true})
   -> 0.0448s
-- create_table("users", {:force=>true})
   -> 0.0464s
-- add_index("users", ["email"], {:unique=>true, :name=>"index_users_on_email"})
   -> 0.0502s
-- initialize_schema_migrations_table()
   -> 0.0016s
-- assume_migrated_upto_version(20110814141025, "db/migrate")
   -> 0.0024s
lithium@ubuntu:~/blog$ rake db:migrate
==  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, "name" varchar(255), "email" varchar(255), "state" varchar(255), "city" varchar(255), "years" integer, "created_at" datetime, "updated_at" datetime)

Tasks: TOP => db:migrate
(See full trace by running task with --trace)




I got past the other issue i posted by simply destroying the table and then rake, but it's annoying to have to do that ***** again.

Last edited by _lithium_ (2011-08-15 17:57:39)

Re: Need help please

I got it working, but only because I go into SQLITE from the terminal, drop the User table, then do a rake db:migrate...wtf?

Re: Need help please

Just in case anyone else is struggling with this spot in Michael Hartl's tutorial . . . you're not alone. I have no idea why he doesn't update his tutorial to address this issue . . .

Here's what I did: skip that first bundle exec rake db:migrate.

Follow along with all the validation stuff. (I'm skipping the testing stuff so I don't know if that will screw things up by not doing this rake.)

Be sure to do this in section 6.22:
class AddIndexToUsersEmail < ActiveRecord::Migration
  def change
    add_index :users, :email, unique: true
  end
end

Then do bundle exec rake db:migrate. This will work because the users table will be created now, not back at the beginning of the chapter.

Not sure what will happen when I get further into the tutorial because I see that this same issue rears it's head again.

If anybody knows Michael Hartl, please call him up and ask him to address this issue. He's got a lot of people paying for his tutorial, including me, and this isn't acceptable.

Last edited by charliemagee (2012-05-23 18:38:01)

Re: Need help please

I think that's clear enough.

User table is already existed, drop that table and try to run it again.

Re: Need help please

Nice information and also thanks for for shared with us.!!!I totally agree with your post..!!