验证在YII中不起作用
这是我的代码:验证在YII中不起作用,yii,Yii,这是我的代码: public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('ScriptName,TestSystem_id', 'required'), array('T
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('ScriptName,TestSystem_id', 'required'),
array('TestSystem_id, TmatsUser_id, Active', 'numerical', 'integerOnly'=>true),
array('ScriptName, TestObjective, ScriptFormat, ComponentImpact', 'length', 'max'=>120),
array('Description, ScriptCode, ProvisionReq', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, TestSystem_id, TmatsUser_id, ScriptCode, ProvisionReq, ScriptName, Description, ScriptFormat, Active', 'safe', 'on'=>'search'),
);
}
但是验证不起作用。它给出了以下错误
CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'TestSystem_id' cannot be null
它根本不验证脚本名
在数据库中,这两个参数都被指定为NOTNULL
其他形式的验证工作正常
非常感谢您的帮助。该错误意味着您在数据库中的某个表中存储了存储在该表中的外键的主键…并且您试图在另一个表的主键列中不存在的外键列中存储某些值。因此,数据库完整性约束违规事件发生了。。。 或者从数据库中删除数据库约束,因为我们将它们与模型一起使用,所以它们不是必需的
并确保您正在存储父表主键列中的数据。谢谢。我会调查的。