mardi 10 novembre 2020

rake db:seed error- uninitialised constant

I came across the following error when running rake db:seed:

Running via Spring preloader in process 26002 rake aborted! NameError: uninitialized constant Location /mnt/c/Users/raeye/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/cpde/weatherapp/db/seeds.rb:9:in <main>' -e:1:in ' Tasks: TOP => db:seed (See full trace by running task with --trace)

Seed file:

l = Location.create(name: "New York City")
l.recordings.create(temp: 32, status: "cloudy")
l.recordings.create(temp: 28, status: "rainy")
l.recordings.create(temp: 30, status: "sunny")
l.recordings.create(temp: 31, status: "rainy")

Location:

class Location < ApplicationRecord
  has_many :recordings
end

Recording:

class Recording < ApplicationRecord
  belongs_to :location
end

timestamp files

class CreateLocations < ActiveRecord::Migration[6.0]
  def change
    create_table :locations do |t|
      t.string :name

      t.timestamps
    end
  end
end

class CreateRecordings < ActiveRecord::Migration[6.0]
  def change
    create_table :recordings do |t|
      t.references :location, null: false, foreign_key: true
      t.integer :temp
      t.string :status

      t.timestamps
    end
  end
end

I'm thinking that it could due to naming convention error, can anyone shed some light on this?

Aucun commentaire:

Enregistrer un commentaire