ruby-on-rails - Ruby on Rails:未加载种子数据
问题描述
我正在尝试为用户、作品和评论播种数据,但是当我查询数据库时,唯一可用的数据是用户。在为 Works 和 Comments 格式化我的代码时,我做错了什么吗?我正在做一个有很多,通过评论是我的连接表的关系。
{ title:"Guernica", artist: "Pablo Picasso", year: "1937", medium: "oil"},
{ title: "The Birth of Venus", artist: "Sandro Botticelli", year: "1485", medium: "tempera"},
{ title: "The Kiss", artist: "Gustav Klimt", year: "1907", medium:"oil"},
{ title: "American Gothic", artist: "Grant Wood", year: "1930" , medium: "oil"},
{ title: "Nighthawks", artist: "Edward Hopper", year: "1942", medium: "oil"},
{ title: "The Nightwatch", artist: "Rembrandt", year: "1642" , medium: "oil"},
{ title: "Campbell's Soup Cans", artist: "Andy Warhol" , year: "1961" , medium: "syntheic polymer paint"},
{ title: "The Great Wave off Kanagawa", artist: "Hokusai", year: "1820" , medium: "print"},
{ title: "David", artist:"Michelangelo", year: "1501" , medium: "marble"}])
Comment.create({headline:"Comment 1", description: "I think this piece is in France"})
Comment.create({headline:"Comment 2", description: "This is actually a huge work of art in person"})
Comment.create({headline:"Comment 3", description: "Why is this artist known for this piece?"})
Comment.create({headline:"Comment 4", description: "Would this be more iconic if done in another medium?"})
Comment.create({headline:"Comment 5", description: "What does the title mean?"})
Comment.create({headline:"Comment 6", description: "me lol"})
Comment.create({headline:"Comment 7", description: "Game of thrones reference"})
Comment.create({headline:"Comment 8", description: "I could've made that!"})
Comment.create({headline:"Comment 9", description: "what artists were inspired by this piece?"})
Comment.create({headline:"Comment 10", description: "proportions"})'''
Here's my schema:
create_table "comments", force: :cascade do |t|
t.string "headline"
t.string "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "user_id"
t.integer "work_id"
end
create_table "users", force: :cascade do |t|
t.string "email"
t.string "password_digest"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "works", force: :cascade do |t|
t.string "title"
t.string "artist"
t.text "year"
t.string "medium"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end```
解决方案
推荐阅读
- c# - 解密 Magtek EMV 数据
- html - 如何在高度变化时保持边界半径形状
- c# - 使用样板 ASP.Net 核心进行外部身份验证?
- apache - MAMP Pro / APACHE / PHP 没有为 Fetch OPTIONS 预检请求返回 OK
- angular - 在角度的 for 指令中使用 if 指令
- java - JSON 路径:如何将 URN 引用转换为本地引用
- scikit-learn - sklearn LabelEncoder inverse_transform TypeError:只能将整数标量数组转换为标量索引
- python-3.6 - 使用带有 Visual Studio 代码错误的 python 3.6 在生产 azure function 2.0 中部署
- r - 如何检查时间组是否在R中是顺序的
- c# - 通过 CloudTable.CreateQuery 创建的查询可能无法调用流利的方法
()