Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails创建记录失败_Ruby On Rails_Activerecord - Fatal编程技术网

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