LoginSignup
0
0

More than 1 year has passed since last update.

rails g devise User を実行の際のエラーの話

Posted at

背景

rails g devise User を実行の際、以下のエラーが発生

rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateColumn: ERROR:  column "email" of relation "users" already exists

エラー文を見ると、どうやらusersテーブルが重複しているようだ。

試した事

rails db:migrate:reset
しかし、

rails aborted!
ActiveRecord::NoEnvironmentInSchemaError: 

Environment data not found in the schema. To resolve this issue, run: 

        bin/rails db:environment:set RAILS_ENV=development

以上のようなエラーが発生。
binは一切弄っていないので他に原因がありそう。

解決方法

  • 対象モデルを削除する
rails destroy devise user
  • 次にテーブルを削除するために、削除用のmigrationファイルを作成する
rails g migration drop_table_users(←適当なファイル名で可)
  • 作成したmigrationファイルにテーブル削除を記述する
class DropTableUsers < ActiveRecord::Migration
 def change
  drop_table :users
 end
end
  • マイグレーション実行
rails db:migrate
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0