LoginSignup
onaka0_0suita
@onaka0_0suita (m- yuto)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

【Rails】ローカル環境では正常に動作するのですが、AWSにデプロイするとMysql2::Error: Unknown columnのerrorが出ます。

解決したいこと

ローカル環境ではアクセス出来るのですが、AWSにデプロイすると、下記のエラーが発生しました。

発生している問題・エラー

We're sorry, but something went wrong.

そこで、productionlogを確認したところ、下記のエラーが表示されました。

ActionView::Template::Error (Mysql2::Error: Unknown column 'start_on' in 'where clause'):
106:   </div>
107:   <div class="top_news_flex">
108:
109:     <% @admin_news.first(4).each do |admin| %>
110:       <div class="top_news_contents">
111:         <%= link_to newsDetail_skip_path(admin.id) do %>
112:           <div class="top_news_img">

app/views/skips/index.html.erb:109

該当するソースコード

admins_controller.rb
def set_item
  @admin_news = Admin.where('start_on <= ?', Date.today).order("created_at DESC")
end
index.html.erb
<% @admin_news.first(4).each do |admin| %>
  <div class="top_news_contents">
    <%= link_to newsDetail_skip_path(admin.id) do %>
      <div class="top_news_img">
        <%= image_tag admin.image if admin.image.attached? %>
      </div>
      <div class="top_news_info">
        <time>
          <%= admin.start_on.strftime("%Y.%m.%d") %>
        </time>
        <h4>
          <%= admin.title.truncate(12) %>
        </h4>
        <p>
          <%= strip_tags(admin.content.to_s).gsub(/[\n]/,"").strip.truncate(60) %>
        </p>
      </div>
    <% end %>
  </div>
<% end %>
migtate.file
class CreateAdmins < ActiveRecord::Migration[6.0]
  def change
    create_table :admins do |t|
      t.string :title,    null: false
      t.date :start_on,   null: false
      t.references :user, null: false, foreign_key: true

      t.timestamps
    end
  end
end

自分で試したこと

同じようなエラーが出ている方の記事を参考にしてみたのですが、原因箇所が異なっていたりで、解決には繋がりませんでした。

何か原因が分かる方がいらっしゃいましたら、ご教授頂けますと幸いです。
よろしくお願いいたします。

0

1Answer

Your answer might help someone💌