rails 未初始化常量 db:seed
rails Uninitialized constant db:seed
我正在尝试为我的 rails api 播种,我已经迁移了脚手架并且可以在我的本地主机上创建条目。
我也尝试将其更改为每个模型的人和汽车,但这也不起作用。
我的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
我试过为每个模型将其更改为 Person 和 Car,但这也不起作用。我也试过 运行ning 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
People = [ {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'} ]
People.each do |p|
Person.create! p
end
还要检查您的模型名称,它应该是 Person
我正在尝试为我的 rails api 播种,我已经迁移了脚手架并且可以在我的本地主机上创建条目。 我也尝试将其更改为每个模型的人和汽车,但这也不起作用。
我的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
我试过为每个模型将其更改为 Person 和 Car,但这也不起作用。我也试过 运行ning 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
People = [ {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'} ]
People.each do |p|
Person.create! p
end
还要检查您的模型名称,它应该是 Person