Mysql2::Error: Field 'USER_NAME' doesn't have a default value: INSERT INTO `dashboard_user` VALUES()
我得到當我試圖打開我的網頁http//127.0.0.1:3000/my/user_creation
Rails的錯誤有一個值
有人可以幫助這個這個錯誤?
下面是模型
class CreateDashboardUsers < ActiveRecord::Migration
def change
create_table "dashboard_user", primary_key: "USER_ID", force: true do |t|
t.string "USER_NAME", limit: 50, null: false
t.string "NORMALIZED_USER_NAME", limit: 50
t.string "PASSWORD", limit: 50
t.string "LAST_NAME", limit: 50
t.string "FIRST_NAME", limit: 50
t.string "MIDDLE_NAME", limit: 50
t.string "PHONE", limit: 15
t.string "EMAIL_ID", limit: 100
t.integer "SEQ_QUES_ID"
t.string "SEQ_QUES_ANSWER", limit: 100
t.string "EXPIRE_PASSWORD_IND", limit: 1
t.date "EXPIRE_PASSWORD_DATE"
t.string "DEACTIVATED_IND", limit: 1
t.date "DEACTIVATED_DATE"
t.integer "ROLE_ID"
t.string "CREATED_BY", limit: 50
t.datetime "CREATED_DATE"
t.string "UPDATED_BY", limit: 50
t.datetime "UPDATED_DATE"
end
end
end
控制器代碼低於
class AdminController < ApplicationController
def user_creation
DashboardUser.create(:USER_NAME => params[:username])
DashboardUser.create(:PASSWORD => params[:password])
DashboardUser.create(:LAST_NAME => params[:lastname])
DashboardUser.create(:FIRST_NAME => params[:firstname])
DashboardUser.create(:MIDDLE_NAME => params[:middlename])
DashboardUser.create(:PHONE => params[:phone])
redirect_to :action => 'user_creation'
end
private
def dashboard_params
params.require(:dashboard_user).permit(:id, :user_name, :password, :last_name, :first_name, :middle_name , :phone)
end
end
Mysql2 ::錯誤:字段 'USER_NAME' 不具有默認值:INSERT INTO dashboard_user
VALUES()此是我在瀏覽器中運行它時得到的結果
dashboard_user
class DashboardUser < ActiveRecord::Base
self.table_name = "dashboard_user"
end
郵報user_creation行動(或任何行動這個URL路由)的代碼。同時從mysql控制檯發佈'desc dashboard_user'的結果。 – atmaish 2014-10-01 11:22:49
添加了user_Creation和dashboard_user – 2014-10-01 12:00:08
沒有在CRUD上讀過呢? – Richlewis 2014-10-01 12:51:30