title: How do I seeds sqlite3 data base in rails activerecord?
body: <p>I'm trying to populate the flight table through the seed.rb file on sqlit3 db in rails ActiveRecord with the following code:</p>
  <pre><code>   departure = Date.new(2021, 9, 1)
     arrival = Date.new(2021, 10, 1)
  
    (departure).upto(arrival).each do |flight_schedule|
     airports.each do |origin|
      airports.each do |destination|
        if origin == destination
          next
        else
          3.times { Flight.create(origin: origin,
                                  destination: destination,
                                  flight_schedule: flights_time,
                            duration: flights_duration(origin.code, destination.code))}
        end
       end
      end
     end
  </code></pre>
  <p>I have a many to many relationships set up between the airport and flight model with references (foreign_key) as follows;</p>
  <pre><code>class Airport &lt; ApplicationRecord
      has_many :departures, 
               class_name: :Flight, 
               foreign_key: :origin_id, 
               dependent: :destroy
  
      has_many :arrivals, 
               class_name: :Flight,  
               foreign_key: :destination_id, 
               dependent: :destroy
  end
  
  class Flight &lt; ApplicationRecord
    belongs_to :origin, class_name: :Airport
    belongs_to :destination, class_name: :Airport
    
  end
  </code></pre>
  <p>Here is the the db schema;</p>
  <pre><code>ActiveRecord::Schema.define(version: 2021_07_21_232515) do
  
    create_table &quot;airports&quot;, force: :cascade do |t|
      t.string &quot;code&quot;
      t.string &quot;location&quot;
      t.datetime &quot;created_at&quot;, precision: 6, null: false
      t.datetime &quot;updated_at&quot;, precision: 6, null: false
    end
  
    create_table &quot;flights&quot;, force: :cascade do |t|
      t.integer &quot;origin_id&quot;, null: false
      t.integer &quot;destination_id&quot;, null: false
      t.integer &quot;duration&quot;
      t.datetime &quot;flight_schedule&quot;
      t.datetime &quot;created_at&quot;, precision: 6, null: false
      t.datetime &quot;updated_at&quot;, precision: 6, null: false
      t.index [&quot;destination_id&quot;], name: &quot;index_flights_on_destination_id&quot;
      t.index [&quot;origin_id&quot;], name: &quot;index_flights_on_origin_id&quot;
    end
  
    add_foreign_key &quot;flights&quot;, &quot;destinations&quot;
    add_foreign_key &quot;flights&quot;, &quot;origins&quot;
  end
  </code></pre>
  <p>When I run rails db:seed
  I have these errors:</p>
  <pre><code>Rails aborted!
  ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: main.destinations
  </code></pre>
  <p>Rails version 6.1.4
  Ruby version 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]</p>