0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【エラー】管理者画面(Active Admin)に新たに管理するモデルを追加する際に経験したエラー

Posted at

はじめに

新たに管理するモデルを追加しようとした際に、エラーが出てしまった時の備忘録記事となります。
インストールの詳細は省きます。

同じ現象であれ?となった人の解決きっかけになれればと思います。
ActiveAdmin 特有のエラーではありません。その他エラーの際にも参考になれば幸いです。
  

環境

macOS Bigsur
Rails 6.1
Ruby 2.7

インストール

  • gemfile に追記
gem 'activeadmin'
gem 'devise'
gem 'rails-i18n', '~> 6.0'
gem 'devise-i18n'
  • ターミナルで実行
bundle install

エラー

【今回追加するモデル】 Movie

uninitialized constant モデル名 (NameError) Did you mean?

  • 初期化されていない定数があるときにエラーが発生

  • 管理者画面で管理するデータを登録するテーブルがないときにエラーが発生
    (例) uninitialized constant Movie(NameError) Did you mean?

  • 下記を実行しテーブルを作成することで解決

rails g model User
rails db:migrate

conflict config/initializers/devise.rb Overwrite /Users/ユーザー名/アプリ名/config/initializers/devise.rb? (enter "h" for help) [Ynaqdhm]

  • rails g devise:install を インストールしてから rails g active_admin:installをインストールしないとdevise.rbファイルがコンフリクトする

  • [Ynaqdhm]の後に入力を求められるので、問題がなければ y を入力することで上書きできる。

PG::DuplicateTable: ERROR:

  • テーブルが重複しているときに発生
  • エラー詳細
    • (例)movies が重複
rails db:migrate
== 20210605042245 CreateMovies: migrating =====================================
-- create_table(:movies)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR:  relation "movies" already exists
  • データベースの重複しているテーブルを削除することで解決
drop table テーブル名;
rails db:migrate

(例) movies テーブルを削除

drop table movies;

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?