0

I want do run migration on my app that I have on heroku but I get this error:

Running `rake db:migrate` attached to terminal... up, run.1
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
Migrating to CreateUsers (20120525005302)
Migrating to DeviseCreateUsers (20120611000411)
==  DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR:  relation "users" already exists
: CREATE TABLE "users" ("id" serial primary key, "email" character varying(255) DEFAULT '' NOT NULL, "encrypted_password" character varying(255) DEFAULT '' NOT NULL, "reset_password_token" character varying(255), "reset_password_sent_at" timestamp, "remember_created_at" timestamp, "sign_in_count" integer DEFAULT 0, "current_sign_in_at" timestamp, "last_sign_in_at" timestamp, "current_sign_in_ip" character varying(255), "last_sign_in_ip" character varying(255), "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 

Tasks: TOP => db:migrate

I have the following migration files in my github repository

  1. 20120525005302_create_users.rb (which is empty, dont know how to remove it)
  2. 20120611000411_devise_create_users.rb
  3. 20120613140535_create_authentications.rb

2 Answers2

2

It looks like the following is true:

  • 20120525005302_create_users.rb will attempt to create a users table in your database.
  • 20120611000411_devise_create_users.rb will also attempt to create a users table in the database.
  • Your database currently already has a users table in it, so the migration fails on the second migration.

To get the users table in your database to correspond properly to the 20120611000411_devise_create_users.rb migration, you can do one of two things:

  1. Roll back (or drop) the database, and then run the migrations again. (You can delete the 20120525005302_create_users.rb if it is empty.)
  2. Modify your 20120611000411_devise_create_users.rb migration to drop any existing users table before doing anything else.
  3. Modify your 20120611000411_devise_create_users.rb migration as follows:
    • Instead of creating a users table, modify the existing table.
    • Add and modify database components to correspond

Generally, if your application is in an "infant state," then re-creating the database tends to be a quick way to build the initial structure of an application. However if you already have important data in your users table, you'll want to keep that and proceed by modifying the 20120611000411_devise_create_users.rb migration to change the database non-destructively.

References

fdsaas
  • 714
  • 4
  • 10
  • I rollbacked all the migration, i dont have the first migration and I pushed everthing upp to github put it still is there.. –  Jun 13 '12 at 22:16
  • I have now removed the migration file, still get the same error. –  Jun 13 '12 at 22:49
  • Sounds like the easiest approach would be to apply the changes to your server's database from a fresh database. Also, if you change the behavior of `20120611000411_devise_create_users.rb`, good practice would be to change its name to reflect the behavior (that is, something like `20120611000411_devise_modify_users.rb` or whatever.) – fdsaas Jun 15 '12 at 20:24
1

It looks like you already have table users (probably from create_users migration) that device_create_users is trying to recreate

You can modify your create_device_users migration to just add the fields that you need

Alternatively if its a brand new app with no users you can just drop and try re running all the migraions

Yuriy Goldshtrakh
  • 2,014
  • 1
  • 11
  • 7
  • Cant I just delete that migration from my app and github resp.. How do I do that? –  Jun 13 '12 at 21:57
  • 1
    git rm 20120525005302_create_users.rb git push origin master heroku run rake db:drop heroku run rake db:create heroku run rake db:migrate – Yuriy Goldshtrakh Jun 13 '12 at 22:53