0

herokuにあるアプリで移行を実行したいのですが、次のエラーが発生します。

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

githubリポジトリに次の移行ファイルがあります

  1. 20120525005302_create_users.rb(これは空です。削除する方法がわかりません)
  2. 20120611000411_devise_create_users.rb
  3. 20120613140535_create_authentications.rb
4

2 に答える 2

2

次のように見えます。

  • 20120525005302_create_users.rbusersデータベースにテーブルを作成しようとします。
  • 20120611000411_devise_create_users.rbusersまた、データベースにテーブルを作成しようとします。
  • 現在、データベースにはすでにusersテーブルが含まれているため、2回目の移行で移行は失敗します。

データベース内のusersテーブルを移行に適切に対応させるには20120611000411_devise_create_users.rb、次の2つのいずれかを実行できます。

  1. データベースをロールバック(またはドロップ)してから、マイグレーションを再実行してください。20120525005302_create_users.rb(空の場合は削除できます。)
  2. 移行を変更して、他の作業を行う前に20120611000411_devise_create_users.rb既存のテーブルを削除します。users
  3. 20120611000411_devise_create_users.rb次のように移行を 変更します。
    • テーブルを作成する代わりにusers、既存のテーブルを変更します。
    • 対応するデータベースコンポーネントを追加および変更します

一般に、アプリケーションが「初期状態」にある場合、データベースを再作成することは、アプリケーションの初期構造を構築するための迅速な方法になる傾向があります。ただし、テーブルにすでに重要なデータがある場合は、それを保持し、データベースを非破壊的に変更するように移行を変更してusers続行することをお勧めします。20120611000411_devise_create_users.rb

参考文献

于 2012-06-13T21:57:42.920 に答える
1

device_create_usersが再作成しようとしているテーブルユーザー(おそらくcreate_usersの移行から)がすでに存在するようです

create_device_usersの移行を変更して、必要なフィールドを追加することができます

または、ユーザーがいない新しいアプリの場合は、ドロップしてすべての移行を再実行してみてください

于 2012-06-13T21:42:47.603 に答える