rails 列不能为空: [英] rails Column cannot be null:

查看:67
本文介绍了rails 列不能为空:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我的应用程序会自动将所有进程设置为在创建后立即完成.我查看了它,找不到为什么在没有被告知的情况下更新日期,但我发现我的一个观点正在寻找一个不存在的字段.我创建了完整"字段,将其设置为非空布尔值,然后再试一次.

I noticed that my application was automatically setting all my processes to having been completed as soon as they were created. I looked through it, couldn't find why the date was being updated without being told to, but I found that one of my views was looking for a field that didn't exist. I created the 'complete' field, set it as a not null boolean and tried again.

我再次将其自动设置为 true,因此我尝试在 create 方法中将其显式设置为 false,但这仍然不起作用 :S 所以我尝试将隐藏字段放入表单中.即使提供了值,我现在也收到列不能为空"错误.

I was getting it being set automatically to true again so I tried setting it as false explicitly in the create method, this still didn't work :S so I tried putting a hidden field into the form. I am now getting a "column cannot be null" error even though the value is being provided.

如您所见,完整值显然有一个参数.我错过了什么?

As you can see there is clearly a parameter for the complete value. What am I missing?

错误:

Mysql::Error: Column 'complete' cannot be null: INSERT INTO `decommissions` (`completed_at`, `keep_backups`, `services_stopped`, `updated_at`, `operating_system_id`, `comments`, `username`, `disposition`, `stakeholder_email`, `complete`, `alias`, `storage`, `model_id`, `contract_maintenance`, `created_at`) VALUES(NULL, 1, 1, '2010-10-18 00:32:37', 1, NULL, NULL, '', 'test@qut.edu.au', NULL, 'test1', '', 1, '', '2010-10-18 00:32:37')

参数:

{"decommission"=>{"dns_items_attributes"=>{"0"=>{"ip"=>"131.181.185.111",
 "alias"=>"test",
 "retain"=>"1",
 "_destroy"=>""}},
 "keep_backups"=>"1",
 "services_stopped"=>"1",
 "operating_system_id"=>"1",
 "stakeholder_email"=>"test@qut.edu.au",
 "alias"=>"test1",
 "model_id"=>"1"},
 "commit"=>"Submit",
 "authenticity_token"=>"cMMf0zS/5jPExlXqVPaYVXndqPeVkm+OQ/WEPIYd2+g=",
 "disposition"=>"Dispose",
 "complete"=>"false",
 "storage"=>"Local",
 "contract_maintenance"=>"0"}

当我将以下内容放入我的创建控制器时,它呈现真":

When I put the following in my create controller it renders 'true':

@decommission = Decommission.new(params[:decommission])
@decommission.complete = false
render :text => @decommission.complete

推荐答案

@zetetic

我确实有一个名为 complete 的方法,我重命名了它,但问题仍然存在.

I did have a method called complete, I renamed this but the problem was still occurring.

以下所有值均出现问题:处置"=>处置",完成"=>假",存储"=>本地",contract_maintenance"=>0"

The problem occurred for all the following values: "disposition"=>"Dispose", "complete"=>"false", "storage"=>"Local", "contract_maintenance"=>"0"

这些值是使用普通形式选择器而不是 rails 选择器接收的.这是我唯一能找到的他们的共同点.我最终运行了一些实验测试,发现这些值并没有存储在退役对象中,而是存储在它们自己中.

These values were received using normal form selectors rather than rails ones. That was the only thing I could find that they had in common. I ended up running some experimental tests and found that the values were not being stored withing the decommission object, but rather in their own.

因此,在控制器中,我运行了一些额外的行来将退役对象中的值设置为等于与其关联的参数:

So in the controller I ran a few extra lines to set the values within the decommission object to equal the parameters associated with it:

@decommission.storage = params[:storage]
@decommission.contract_maintenance = params[:contract_maintenance]
@decommission.disposition = params[:disposition]
@decommission.complete = false

这篇关于rails 列不能为空:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆