我有text
和token
字段模型question
。希望通过脚手架将数据添加到此中。问题的MYSQL(INSERT)
这是我question_控制器
def create
# @question = Question.new(params[:question])
@question = Question.create(:text => params[:text], :security_token => Digest::SHA1.hexdigest(rand(1000000).to_s))
render :json => @question.to_ext_json(:success => @question.save)
end
当我按下“添加”按钮我在控制台中看到这一点:
Question Create (0.0ms) Mysql::Error: Column 'text' cannot be null: INSERT INTO `questions` (`created_at`, `updated_at`, `text`, `security_token`) VALUES('2011-04-05 09:07:37', '2011-04-05 09:07:37', NULL, 'bf44551f11ce202b88d521a1826ab6db4254ce55')
为什么列“文字”不能为空?
它不能为空,因为表定义不让它为空。另外,在MySQL中为列名使用保留字是不好的做法。改变你的表并删除那个特定列定义的“NOT NULL”部分。 – 2011-04-05 09:15:36