Ruby on rails Rails创建记录失败
这是我的桌子结构Ruby on rails Rails创建记录失败,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,这是我的桌子结构 class CreateStudentAssignments < ActiveRecord::Migration[5.1] def change create_table :student_assignments do |t| t.string :title t.string :subject t.text :description t.float :amount, default: 0 t.date
class CreateStudentAssignments < ActiveRecord::Migration[5.1]
def change
create_table :student_assignments do |t|
t.string :title
t.string :subject
t.text :description
t.float :amount, default: 0
t.date :start_date
t.date :due_date
t.integer :word_count
t.time :approximate_estimated_duration
t.boolean :active, default: true
t.float :overall_rating
t.integer :view_count, default: 0
t.boolean :assignment_approved, default: false
t.references :assignment_status, foreign_key: true
t.references :student, foreign_key: { to_table: :users }
t.references :difficulty_level, foreign_key: true
t.references :writer, foreign_key: { to_table: :users } # Assignment accepted writer
t.timestamps
end
end
end
如何传递该用户
提前感谢检查您的模式(rake db:schema:dump)是否在student\u Assignments表中创建了student\u id,或者运行
StudentAssignment.new
您将看到所有模型属性(即列)。检查您的模式(rake db:schema:dump)是否在student\u Assignments表中创建了student\u id,或者运行StudentAssignment.new
,您将看到所有模型属性(即列)。
p = {title: "title", subject: "subject", description: "des", amount: 5.00, start_date: Date.today + 1, due_date: Date.today + 5, word_count: 100, approximate_estimated_duration: 1000, overall_rating: 4, view_count:4, assignment_status: AssignmentStatus.last, difficulty_level_id: 4, student: User.last}
StudentAssignment.create(p).errors
ActiveModel::MissingAttributeError: can't write unknown attribute `student_id`
from (irb):56