rails: ActiveModel::MissingAttributeError: can't write unknown attribute `division_id`

rails: ActiveModel::MissingAttributeError: can't write unknown attribute `division_id`

我正在开发一个简单的支持票系统,但是我遇到了一个奇怪的错误。这是错误:

ActiveModel::MissingAttributeError: 无法写入未知属性 division_id

这是代码:

user.rb:

  class User < ApplicationRecord
  belongs_to :division
  has_many :teckets
  has_many :teckets , through: :user_tecket

  has_secure_password
end

division.rb:

 class Division < ApplicationRecord
  has_many :users
  has_many :users, through: :user_division
  has_many :teckets
  has_many :teckets, through: :teckets_divisions
end

tecket.rb :

class Tecket < ApplicationRecord
  belongs_to :division
  belongs_to :user
  has_one :status
  has_one :status, through: :tecket_statuses
end

teckets_division.rb :

class TecketsDivision < ApplicationRecord
  belongs_to :tecket
  belongs_to :division
end

schema.rb:

ActiveRecord::Schema.define(version: 20171001063612) do

  create_table "divisions", force: :cascade do |t|
    t.string "name"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "replies", force: :cascade do |t|
    t.string "content"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "statuses", force: :cascade do |t|
    t.string "title"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "tecket_replies", force: :cascade do |t|
    t.integer "tecket_id"
    t.integer "reply_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "tecket_statuses", force: :cascade do |t|
    t.integer "tecket_id"
    t.integer "status_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "teckets", force: :cascade do |t|
    t.string "title"
    t.string "content"
    t.string "platform"
    t.string "version"
    t.string "client_anme"
    t.string "client_phone"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "teckets_divisions", force: :cascade do |t|
    t.integer "tecket_id"
    t.integer "division_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "user_divisions", force: :cascade do |t|
    t.integer "user_id"
    t.integer "division_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "user_teckets", force: :cascade do |t|
    t.integer "user_id"
    t.integer "tecket_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "users", force: :cascade do |t|
    t.string "name"
    t.string "email"
    t.string "passwrod"
    t.string "password_digest"
    t.integer "division_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

end

当我尝试从控制台创建用户时出现错误

编辑:我已经按照要求添加了schema.rb文件

从用户 table 中删除 division_id 并从部门模型中删除 has_many :users

或(以及更简单的方法),

删除 user_divisions 加入 table 并且这一行来自部门模型:

has_many :users, through: :user_division

还有 - 您似乎有很多连接 tables,但我认为没有必要使用它们。在你展示的大多数情况下,你可以直接将它们联系起来。