質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

Q&A

解決済

2回答

1157閲覧

Herokuへのデプロイができない

tomsuma

総合スコア38

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

0グッド

0クリップ

投稿2020/08/29 23:32

編集2020/08/30 00:46

Herokuにて再デプロイを試みたところ、
エラーがおきました。。

no fileのマイグレーションファイルに
touch db/migrate/20200811115754_hoga.rb
コマンドにてファイルの置き換えを試みたのですがダメでした、、、

Status Migration ID Migration Name -------------------------------------------------- (2.6ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC up 20200805054129 Devise create users up 20200805061051 Create sns credentials up 20200808070314 Create books up 20200808070822 Create active storage tablesactive storage up 20200810072111 ********** NO FILE ********** up 20200811115754 ********** NO FILE ********** up 20200811131113 ********** NO FILE ********** down 20210810072111 Create messages down 20210810072112 Create favorites heroku run rails db:rollback ActiveRecord::UnknownMigrationVersionError: heroku run rails db:migrate Index name 'index_messages_on_book_id' on table 'messages' already exists

heroku run rails db:migrate:resetもダメでした。。

ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database. If you are sure you want to continue, run the same command with the environment variable: DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/tasks/database_tasks.rb:63:in `check_protected_environments!' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/railties/databases.rake:15:in `block (2 levels) in <main>' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:20:in `perform' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/command.rb:48:in `invoke' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands.rb:18:in `<main>' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require' /app/bin/rails:9:in `<main>' Tasks: TOP => db:migrate:reset => db:drop => db:check_protected_environments (See full trace by running task with --trace)
schema.rb create_table "favorites", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.integer "user_id" t.integer "book_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["user_id", "book_id"], name: "index_favorites_on_user_id_and_book_id", unique: true end create_table "messages", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.text "text" t.bigint "book_id" t.bigint "user_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end
rollback heroku run rails db:rollback Running rails db:rollback on ⬢ books-28291... up, run.1599 (Free) DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <main> at /app/config/application.rb:7) (2.1ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483 (3.7ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC (2.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC (2.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC rails aborted! ActiveRecord::UnknownMigrationVersionError: No migration with version number 20200811131113. /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1169:in `move' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/migration.rb:1047:in `rollback' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.3.2/lib/active_record/railties/databases.rake:225:in `block (2 levels) in <main>' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands/rake/rake_command.rb:20:in `perform' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/command.rb:48:in `invoke' /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/commands.rb:18:in `<main>' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require' /app/bin/rails:9:in `<main>' Tasks: TOP => db:rollback

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hatsu

2020/08/30 00:34

``` Index name 'index_messages_on_book_id' on table 'messages' already exists ``` すでにindex_messages_on_book_idという名前のIndexがmessagesテーブルに貼られているようです。 db/migrate/配下のファイルに _book_idを複数回書いてしまっていないかとかを確認するといいかもです。 またはファイル名を書き換えたためにまだマイグレーションしていないファイルだと認識され、再びメッセージテーブルの作成を行おうとしたと思われます。 ファイル名やファイルの中身をいったん全て戻していただき、heroku run rails db:migrate:reset とするといかがでしょうか。
tomsuma

2020/08/30 00:45

ご回答ありがとうございます! メッセージとfavoriteに一つずつあったので消しました! resetやるとエラーが出てしまいます rollbackも同じくです,,,
hatsu

2020/08/30 00:51

本番(=production)環境ではデータベースのDropが保護されています。本番環境でResetやDropを行う際は、DISABLE_DATABASE_ENVIRONMENT_CHECK=1 と書いてあげる必要があります ``` heroku run rails db:migrate:reset DISABLE_DATABASE_ENVIRONMENT_CHECK=1 ```
tomsuma

2020/08/30 04:45

行けました! 本当にありがとうございます
guest

回答2

0

質問で回答が導き出されたので記述します。

問題の整理

Index name 'index_messages_on_book_id' on table 'messages' already exists

すでにindex_messages_on_book_idという名前のIndexがmessagesテーブルに貼られているようです。

  • db/migrate/配下のファイルに _book_idを複数回書いてしまっていないか
  • ファイル名を書き換えたためにまだマイグレーションしていないファイルだと認識され、再びメッセージテーブルの作成を行おうとした

の可能性があります。

解決方法

ファイル名やファイルの中身をいったん全て戻していただき

heroku run rails db:migrate:reset DISABLE_DATABASE_ENVIRONMENT_CHECK=1

とする

投稿2020/08/30 04:49

hatsu

総合スコア1809

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

自己解決

heroku run rails db:migrate:reset DISABLE_DATABASE_ENVIRONMENT_CHECK=1
がheroku相手の時は便利

投稿2020/08/30 04:47

tomsuma

総合スコア38

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問