内容
Railsで開発しているアプリをAWSにデプロイしています。ユーザーフォロー画面にいくと「We're sorry, but something went wrong.」のエラーが出ます。
ログを覗くと「ActionView::Template::Error (Mysql2::Error: Table 'portfolio_development.relationships' doesn't exist: SHOW FULL FIELDS FROM relationships
):」とエラーメッセージが出てきます。
下記の記事を参考に修正しようとしましたが、修正できませんでした。
https://qiita.com/Jwataru/items/7b840be38d4279224245
お力お借りしたいです。
エラーメッセージ
ActionView::Template::Error (Mysql2::Error: Table 'portfolio_development.relationships' doesn't exist: SHOW FULL FIELDS FROM `relationships`): F, [2020-11-23T13:36:11.274578 #3562] FATAL -- : [2fc4ee12-7951-44f4-a7e5-922da7e755af] 1: <% unless current_user == user %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 2: <%if current_user.following?(user) %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 3: <%= form_with(model: current_user.relationships.find_by(follow_id: user.id), local: true, method: :delete) do |f| %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 4: <%= hidden_field_tag :follow_id, user.id %> [2fc4ee12-7951-44f4-a7e5-922da7e755af] 5: <%= f.submit 'フォロー中', class: 'btn btn-primary btn-block' %> F, [2020-11-23T13:36:11.274605 #3562] FATAL -- : [2fc4ee12-7951-44f4-a7e5-922da7e755af] F, [2020-11-23T13:36:11.274628 #3562] FATAL -- : [2fc4ee12-7951-44f4-a7e5-922da7e755af] app/models/user.rb:34:in `following?'
users.hrml.erb
<div class = "card col-lg-5 col-md-7 user_card_main"> <div class= "user_card row"> <div class ="user_card_left"> <% if user.image? %> <%= image_tag user.image.url, class: "rounded-circle", height:"100px" %> <% else %> <%= image_tag "/assets/default.png", class: "rounded-circle", height:"100px" %> <% end %> <div class="follow_button user_card_follow_btn"> <%= render 'relationships/follow_button', user: user %> </div> </div> <div class ="user_card_right"> <table class="table"> <tr> <td>名前 :</td> <td><%=link_to user.name, user_path(user) %></td> </tr> <tr> <td>性別 :</td> <td><%= user.sex %></td> </tr> <tr> <td>年齢 :</td> <td><%= user.age %></td> </tr> <tr> <td>ポジション:</td> <td><%= user.position %></td> </tr> </table> </div> </div> </div>
フォローボタン部分
<% unless current_user == user %> <%if current_user.following?(user) %> <%= form_with(model: current_user.relationships.find_by(follow_id: user.id), local: true, method: :delete) do |f| %> <%= hidden_field_tag :follow_id, user.id %> <%= f.submit 'フォロー中', class: 'btn btn-primary btn-block' %> <% end %> <% else %> <%= form_with(model: current_user.relationships.build, local: true) do |f| %> <%= hidden_field_tag :follow_id, user.id %> <%= f.submit 'フォローする', class: 'btn btn-warning btn-block' %> <% end %> <% end %> <% end %>
usersモデル
class User < ApplicationRecord validates :name, presence: true, length: { maximum: 50 } validates :email, presence: true, length: { maximum: 255 }, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i }, uniqueness: { case_sensitive: false } has_secure_password has_many :microposts has_many :relationships has_many :followings, through: :relationships, source: :follow has_many :reverses_of_relationship, class_name: 'Relationship', foreign_key: 'follow_id' has_many :followers, through: :reverses_of_relationship, source: :user has_many :likes has_many :likings, through: :likes, source: :micropost has_many :joins has_many :joinings, through: :joins, source: :micropost has_many :comments, dependent: :destroy THUMBNAIL_SIZE = [300, 300] mount_uploader :image, ImageUploader def follow(other_user) unless self == other_user self.relationships.find_or_create_by(follow_id: other_user.id) end end def unfollow(other_user) relationship = self.relationships.find_by(follow_id: other_user.id) relationship.destroy if relationship end def following?(other_user) self.followings.include?(other_user) end def like_it(other_micropost) self.likes.find_or_create_by(micropost_id: other_micropost.id) end def unlike_it(other_micropost) favorite = self.likes.find_by(micropost_id: other_micropost.id) favorite.destroy if favorite end def liking?(other_micropost) self.likings.include?(other_micropost) end def joining_event(other_micropost) self.joins.find_or_create_by(micropost_id: other_micropost.id) end def not_joining_event(other_micropost) join = self.joins.find_by(micropost_id: other_micropost.id) join.destroy if join end def joining?(other_micropost) self.joinings.include?(other_micropost) end end
その他
使っているrailsは5.2.4.3です。
フォローボタンを非表示にしたらエラーはなくなりました。
開発環境ではうまく表示されていました。
rails db:migrateをはしましたが治りませんでした。
あなたの回答
tips
プレビュー