我正在嘗試為rails api植入種子,我已經遷移了框架,我可以在本地主機上創建條目。我也試著把它改成人,每種型號的車,但這也不起作用。
my seed.rb:
People.create![
{firstname: 'Josh', lastname: 'Brolin', email: 'jb@gmail.com'},
{firstname: 'Emily', lastname: 'Blunt', email: 'EmilyB@gmail.com'},
{firstname: 'Benicio', lastname: 'Del-Toro', email: 'Sicario@gmail.com'}
]
Cars.create![
{year: '2019', make: 'Audi', model: 'R8', price: '167000', person_id: '1'},
{year: '2010', make: 'Toyota', model: 'Camry', price: '6500', person_id: '2'},
{year: '2009', make: 'Honda', model: 'Civic', price: '4500', person_id: '3'},
{year: '2017', make: 'BMW', model: 'X5', price: '15000', person_id: '2'}
]
當我運行rails db:seed
時,我遇到了這個錯誤:
NameError: uninitialized constant People
/home/pat/Desktop/test/carpeopleback/db/seeds.rb:9:in `<main>'
Tasks: TOP => db:seed
我試著把它改成“人”和“車”兩種型號,但也沒用。我也試過運行rails db:setup
得到同樣的結果
不知道我做錯了什么。謝謝
編輯:這是我的模式:
ActiveRecord::Schema[7.0].define(version: 2022_03_11_224419) do
create_table "cars", force: :cascade do |t|
t.integer "year"
t.string "make"
t.string "model"
t.integer "price"
t.integer "person_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "people", force: :cascade do |t|
t.string "firstname"
t.string "lastname"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
檢查你的型號名稱,它應該是人