Hi folks,
I am newbie for yii, i have two tables like customer,customer detail
In customer (customer_id,cutomer_name,email,…etc)
In customerdetail(customerdetail_id,customer_id,builder_id,…etc).I am using single form for both tables.
the data are stored in first table but not stored in second table,how can i solve this problem,please any one suggest me.I am getting this kind of error
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (myveedudb
.myv_customerdetail
, CONSTRAINT myv_customerdetail_ibfk_1
FOREIGN KEY (myv_customer_id
) REFERENCES myv_customer
(myv_Customer_id
) ON DELETE CASCADE ON UPDATE CASCADE). The SQL statement executed was: INSERT INTO myv_customerdetail
(myv_builder_id
, myv_project_id
, myv_project_block_id
, myv_project_block_floor_id
, myv_apartment_id
, myv_customer_booked_on
, myv_customer_crm_id
) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6)
Here is my code
Controller:
public function actionCreate()
{
$model=new MyvCustomer;
$model2=new MyvCustomerdetail;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['MyvCustomer'],$_POST['MyvCustomerdetail']))
{
$model->attributes=$_POST['MyvCustomer'];
$model2->attributes=$_POST['MyvCustomerdetail'];
$valid=$model->validate();
$valid=$model2->validate() && $valid;
if($valid){
$model->save(false);
$model2->save(false);
}
}
$this->render('create',array(
'model'=>$model,
'model2'=>$model2,
));
}