0

I'm following the RailsTutorial.org tutorial, section 7.3 and trying to do a db migration using rake to add a password column to an existing database. What appears to be happening is that rails is re-running a previous migration file and trying to add table Users (which exists already) rather than the most recent migration file and add a password column. Any help would be appreciated!

Here is the code I ran to generate the migration file:

$ rails generate migration add_password_to_users encrypted_password:string

Then I ran rake db:migrate and got the following error:

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), "created_at" datetime, "updated_at" datetime)
2
  • seems you made a duplicate of a former migration which creates User table. Have a look in your db/migrate folder Commented Jan 24, 2011 at 17:48
  • there should be two migrations containing: create_table :users Commented Jan 24, 2011 at 17:54

2 Answers 2

2

Rails will run any migration whose number is not in the schema_migrations table in the relevant database. So, if it doesn't have the number for the migration to create the users table, it will run that migration, which will blow up as you have seen if the table happens to be there already.

I'm not familiar with the tutorial you're talking about - can you take me through what you have done already with your migrations?

Sign up to request clarification or add additional context in comments.

Comments

0

It appears there was a problem with one of the other migration files -- I moved that file out of the migrate folder and re-ran rake and it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.