user513814
user513814

Reputation: 51

Validations not working in YII

This is my code:

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'),
        );
    }

But the validations doesnt work. It gives the following error

CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'TestSystem_id' cannot be null 

it doesnt validate the ScriptName at all.

In database both are given as NOT NULL.

The validations in other forms works fine.

Any help is appreciated.

Upvotes: 0

Views: 530

Answers (1)

Rajat Singhal
Rajat Singhal

Reputation: 11254

That error means that you have some table in database which stores primary keys of foreign keys you are storing in the table...And you are trying to store some value in the column of foreign key which is not present in the column of primary key in the another table..Hence the database Integrity constraint violation happened... Either remove database constrains from database because we have them with models so they are not required...

And make sure you are storing data which is present in parent table primary key column..

Upvotes: 2

Related Questions