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

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

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

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

Ruby on Rails

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

Q&A

解決済

1回答

1757閲覧

heroku run rails db:migrateで上手くデータベースが反映されません。ご教示いただけないでしょうか。

TARO0811

総合スコア5

Heroku

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

Ruby on Rails

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

0グッド

0クリップ

投稿2020/04/18 09:43

前提・実現したいこと

プログラミング初学者です。
対応策について色々調べましたが、解決できず。
どなたかお力をお貸しいただけますと助かります。。。

① heroku create ○○
② git push heroku master
上記までは、問題なく進んでいたのですが、
heroku run rails db:migrateにて、エラーが発生してしまいました。

発生している問題・エラーメッセージ

エラーメッセージ rails aborted! StandardError: An error has occurred, this and all later migrations canceled: PG::UndefinedColumn: ERROR: column "confirmation_token" does not exist : CREATE UNIQUE INDEX "index_users_on_confirmation_token" ON "users" ("confirmation_token") /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:75:in `async_exec' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:75:in `block (2 levels) in execute' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:74:in `block in execute' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:73:in `execute' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:466:in `add_index' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:871:in `block in method_missing' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:840:in `block in say_with_time' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:840:in `say_with_time' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:860:in `method_missing' /app/db/migrate/20200315234553_devise_create_users.rb:41:in `change' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:814:in `exec_migration' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:798:in `block (2 levels) in migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:797:in `block in migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:796:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:977:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1292:in `block in execute_migration_in_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1343:in `block in ddl_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `block in transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:239:in `block in within_new_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:236:in `within_new_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/transactions.rb:212:in `transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1343:in `ddl_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1291:in `execute_migration_in_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1263:in `block in migrate_without_lock' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1262:in `each' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1262:in `migrate_without_lock' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1210:in `block in migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1363:in `with_advisory_lock' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1210:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1036:in `up' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/migration.rb:1011:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:172:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <main>' /app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/command.rb:48:in `invoke' /app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.1/lib/rails/commands.rb:18:in `<main>' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/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.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/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.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require' /app/bin/rails:9:in `<main>' [以下略] /app/bin/rails:9:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace) ```ここに言語名を入力 ■私の環境 Rails 5.2.4.1 ruby 2.6.5p114 ソースコード

試したこと

heroku rake db:migrate:statusで確認したところ、
deviseで作成した、Userモデルとそのモデルに紐づいているものだけがdownしていることが分かりました。
[実行結果]
down 20200315234553 Devise create users
up 20200316234553 Create goods
up 20200320001554 Create answers
up 20200321045545 Add price to goods
up 20200322074614 Create uploads
up 20200329025030 Create foods
up 20200331133141 Create foodanswers
up 20200404003441 Create shops
up 20200404122834 Create shopers
down 20200405083649 Create profiles
down 20200409124823 Add user id to goods
down 20200409135429 Add user id to foods
down 20200410125803 Add user id to shops
down 20200410131119 Add user id to uploads

エラー文の中にPG::UndefinedColumn: ERROR: column "confirmation_token" does not existと表記があったので、
現状、devise_create_users.rbでは、confirmation_token部分はコメントアウト状態ですが、
外した方が良いのでしょうか。

class DeviseCreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""

## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip t.string :last_sign_in_ip ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts t.string :unlock_token # Only if unlock strategy is :email or :both t.datetime :locked_at t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true add_index :users, :confirmation_token, unique: true add_index :users, :unlock_token, unique: true

end
end

不足情報ございましたら、ご指摘ください。
よろしくお願いいたします。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

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

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

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

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

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

guest

回答1

0

ベストアンサー

この問題に関していえば、herokuは何ら関係ありません。

これをよく読んでみていただきたいと思います。

PG::UndefinedColumn: ERROR: column "confirmation_token" does not exist : CREATE UNIQUE INDEX "index_users_on_confirmation_token" ON "users" ("confirmation_token")
  • column "confirmation_token" does not exist

confirmation_tokenなんていうカラムはないよ

  • CREATE UNIQUE INDEX "index_users_on_confirmation_token" ON "users"

usersテーブルのconfirmation_tokenカラムにuniqueインデックスを作成する

以上がエラー文になります。
つまり、カラムが無いのに、そこにindexを貼ろうとしているからエラーになっています。

migrationファイルのどこかにindexを追加しようとしている行があるはずなので、それを見つけてコメントアウトか削除しましょう。

投稿2020/04/19 01:58

編集2020/04/19 01:59
siruku6

総合スコア1382

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

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

TARO0811

2020/04/22 14:11

ご指摘いただいた箇所確認して無事解決出来ました!ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問