问题
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
- 20120525005302_create_users.rb (which is empty, dont know how to remove it)
- 20120611000411_devise_create_users.rb
- 20120613140535_create_authentications.rb
回答1:
It looks like the following is true:
20120525005302_create_users.rbwill attempt to create auserstable in your database.20120611000411_devise_create_users.rbwill also attempt to create auserstable in the database.- Your database currently already has a
userstable 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:
- Roll back (or drop) the database, and then run the migrations again. (You can delete the
20120525005302_create_users.rbif it is empty.) - Modify your
20120611000411_devise_create_users.rbmigration to drop any existinguserstable before doing anything else. - Modify your
20120611000411_devise_create_users.rbmigration as follows:- Instead of creating a
userstable, modify the existing table. - Add and modify database components to correspond
- Instead of creating a
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
- Running Rake Commands on Heroku
- RailsGuides: Migrations
回答2:
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
来源:https://stackoverflow.com/questions/11023645/heroku-run-rake-dbmigrate-error