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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

Q&A

1回答

687閲覧

herokuデプロイ時のエラー

F.YAMAZAKI

総合スコア0

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

0グッド

0クリップ

投稿2021/04/13 01:24

開発環境:Rails 6.0.3.6

現在railsを使用してアプリを制作しています
先日デプロイした際にローカル環境では正常に動作するが、本番環境ではWe're sorry, but something went wrong.と表示されてしまい繋がりません。

以下、エラーのログになります。

ActionView::Template::Error (Mysql2::Error: Unknown column 'pictures.public_private' in 'where clause'): 39: みんなの投稿一覧 40: </div> 41: <div class="picture-container"> 42: <% unless @pictures.empty? %> 43: <% @pictures.each do |picture| %> 44: <div class="index-contents"> 45: <div class="picture-wrapper"> app/views/pictures/index.html.erb:42

schema.rb

ActiveRecord::Schema.define(version: 2021_04_12_084131) do create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false t.bigint "record_id", null: false t.bigint "blob_id", null: false t.datetime "created_at", null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end create_table "active_storage_blobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "key", null: false t.string "filename", null: false t.string "content_type" t.text "metadata" t.bigint "byte_size", null: false t.string "checksum", null: false t.datetime "created_at", null: false t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end create_table "memos", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.text "info" t.bigint "picture_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.float "offsetX", null: false t.float "offsetY", null: false t.index ["picture_id"], name: "index_memos_on_picture_id" end create_table "pictures", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "text", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.bigint "user_id" t.string "public_private" t.index ["user_id"], name: "index_pictures_on_user_id" end create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "nickname", null: false t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "memos", "pictures" add_foreign_key "pictures", "users" end

migrateログ

Status Migration ID Migration Name -------------------------------------------------- up 20210327025434 ********** NO FILE ********** up 20210327053317 Create pictures up 20210327142737 Create memos up 20210327143912 Devise create users up 20210327151345 Add user to pictures up 20210328111346 Add offsetx to memos up 20210328122030 Change data title to article up 20210328135107 Create active storage tablesactive storage up 20210407031623 Remove public private from pictures up 20210407031743 Add public private from pictures up 20210411132711 Set not null to pictures up 20210412084131 Remove image in pictures

また、本番環境のデータベース確認しましたところ、エラーで指摘されているpublic_privateのカラムがありませんでした。
思い当たる節としましてgitの未プッシュのトピックブランチを右クリックで削除してしまったことです。
そのブランチにpublic_privateカラムを追加するマイグレーションファイルが含まれていました。

ここまで色々な記事を参考に検証しましたが、解決に至りませんでした。
お分かりになる方いらっしゃいましたらご教授お願いいたします。

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

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

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

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

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

guest

回答1

0

書いてある通りでご認識の通りかと思います。

Mysql2::Error: Unknown column 'pictures.public_private' in 'where clause'

このエラー文は意訳すると、「where句の中で'pictures.public_private'っていう条件指定がされてるけど、picturesテーブルにはpublic_privateっていうカラムは無いよ」という意味になります。

そのブランチにpublic_privateカラムを追加するマイグレーションファイルが含まれていました。

マイグレーションファイルがなくなっているのであれば、当然public_privateカラムは作られるはずがありません。
ご自身でご確認なさったとの事で、お分かりかと思います。

完全にご自身で書かれている通りなので、何が疑問なのか分からないのですが、、、笑

再度マイグレーションファイルを作成してherokuにpushすれば良いだけだと思いますが、、、
確かherokuはデプロイ時にマイグレーションファイルを実行してくれたような気がします。設定とかにもよると思いますが。

投稿2021/04/13 05:04

編集2021/04/13 05:06
退会済みユーザー

退会済みユーザー

総合スコア0

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問