title: ActiveModel::MissingAttributeError (can't write unknown attribute `flights_count`):
body: <p>I am doing some refactoring and I have seen this project for a while and it worked from what I last recall. But the issue is, I am trying to create a flight and I keep getting &quot;<em><strong>ActiveModel::MissingAttributeError (can't write unknown attribute <code>flights_count</code>):</strong></em>&quot; when trying create a new flight.</p>
  <p>As far my models in place:</p>
  <p>My Flight, Pilot models</p>
  <pre><code>class Flight &lt; ActiveRecord::Base
      has_many :passengers
      belongs_to :destination
      belongs_to :pilot, counter_cache: true
      accepts_nested_attributes_for :passengers
      belongs_to :user, class_name: &quot;Flight&quot; ,optional: true 
      validates_presence_of :flight_number
      validates :flight_number, uniqueness: true
      scope :order_by_flight_international, -&gt; { order(flight_number: :asc).where(&quot;LENGTH(flight_number) &gt; 3&quot;) }
      scope :order_by_flight_domestic, -&gt; { order(flight_number: :asc).where(&quot;LENGTH(flight_number) &lt;= 2 &quot;) }
      
  
      def dest_name=(name)
          
          self.destination = Destination.find_or_create_by(name: name)
      end
  
      def dest_name
          
          self.destination ? self.destination.name : nil
      end
  
      def pilot_name=(name)
          self.pilot = Pilot.find_or_create_by(name: name)
      end
  
      def pilot_name
          
          self.pilot ? self.pilot.name : nil
      end
  
      
  
  end
  
  
  class Pilot &lt; ActiveRecord::Base
      belongs_to :user, optional: true
      has_many :flights
      has_many :destinations, through: :flights
      
      validates_presence_of :name, :rank
      validates :name, uniqueness: true
      scope :top_pilot, -&gt; { order(flight_count: :desc).limit(1)}
     
  end
  
  </code></pre>
  <p><em><strong>Edit</strong></em>
  Flight Controller</p>
  <pre><code>class FlightsController &lt; ApplicationController
      before_action :verified_user
      layout 'flightlayout'
  
      def index
          @flights = Flight.order_by_flight_international
          @dom_flights = Flight.order_by_flight_domestic
      end
  
      
      
      def new
          @flight = Flight.new
          10.times {@flight.passengers.build}
         
      end
  
      def create
          @flight = Flight.new(flight_params)
          # byebug
          if @flight.save!
    
              redirect_to flight_path(current_user,@flight)
          else
              flash.now[:danger] = 'Flight Number, Destination, and Pilot have to be selected at least'
              render :new
    
             
          end
      end
    private
  
      def flight_params
          params.require(:flight).permit(:flight_number,:date_of_flight, :flight_time, :flight_id, :destination_id, :pilot_id, :pilot_id =&gt;[], :destination_id =&gt;[], passengers_attributes:[:id, :name])
      end
      
      
  end
  </code></pre>
  <p><em><strong>Edit</strong></em>
  Flights, Pilot Schemas</p>
  <pre><code>create_table &quot;flights&quot;, force: :cascade do |t|
      t.integer &quot;pilot_id&quot;
      t.integer &quot;destination_id&quot;
      t.string &quot;flight_number&quot;
      t.string &quot;date_of_flight&quot;
      t.string &quot;flight_time&quot;
      t.datetime &quot;created_at&quot;, null: false
      t.datetime &quot;updated_at&quot;, null: false
    end
  
    create_table &quot;pilots&quot;, force: :cascade do |t|
      t.string &quot;name&quot;
      t.string &quot;rank&quot;
      t.integer &quot;user_id&quot;
      t.integer &quot;flight_id&quot;
      t.datetime &quot;created_at&quot;, null: false
      t.datetime &quot;updated_at&quot;, null: false
      t.integer &quot;flight_count&quot;, default: 0
    end
  
  </code></pre>
  <p>As I said before when I last worked on this project everything was working fine, but I am faced with this issue. What am I doing wrong this time.</p>