実例では、モデルカテゴリがあります。私はウェブサイトでカテゴリを作成しようとすると、私は次のエラーRails、列のnull値がnullでない制約に違反しています
ActiveRecord::StatementInvalid (PG::NotNullViolation: ERROR: null value in column "name" violates not-null constraint
を取得移行は、この
class CreateCategories < ActiveRecord::Migration
def up
create_table :categories do |t|
t.references :supercategory, index: true
t.string :name
t.timestamps null: false
end
Category.create_translation_table! name: :string
end
....
end
とスキーマ
create_table "categories", force: :cascade do |t|
...
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.index ["restaurant_id"], name: "index_categories_on_restaurant_id", using: :btree
t.index ["slug"], name: "index_categories_on_slug", unique: true, using: :btree
t.index ["supercategory_id"], name: "index_categories_on_supercategory_id", using: :btree
end
引き起こしている可能性がありますどのような任意のアイデアのように見えますエラー?ありがとう! もっとコードが必要な場合は、尋ねてください。 { "UTF8" => "✓"、 "authenticity_token" => "no3uGNSYkgClG + y6y9Y ="、 "カテゴリ" => { "名前": のparamsは
パラメータを送っ
EDIT 「0」、「0」、「supercategory_id」=>「」、 「avatar」=>#、 @ original_filename = "coffee.JPG" => "コーヒー"、 "age_restriction" => "0"、"available_all_day" "コンテンツタイプ="イメージ/ jpeg "、 @ヘッダー="コンテンツ - 配置:フォームデータ;名前= \ "カテゴリー[アバター] \"; ファイル名= \ "coffee.JPG \" \ r \ nコンテンツタイプ:image/jpeg \ r \ n ">}、 "コミット " => "Create Category"、 "remotipart_submitted" => "true"、 "X-Requested-With" => "IFrame"、 "X-Http-Accept" => "text/javascript、 アプリケーション/ javascript、アプリケーション/ ecmascript、 アプリケーション/ x-ecmascript、/; Q = 0.01" 、 『restaurant_id』 => 『キリマンジャロ・コーヒー』}
EDIT 私は、コンソールからカテゴリを作成しようとした私は、モデルが名前欄を持っていないことがわかった。それのように思えます
はあなたのコントローラにブレークポイントを追加し、それを保存する前に、新しい 'Category'オブジェクトを検査することができます:あなたはこれではないnullに設定されていると考えているアクティブなどの列レコードを確認することができます? –
私は生産中で、バグはそこにしか現れません。送信されたパラメータを追加しました。 –