[CDbException
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 (blog
.tbl_post
, CONSTRAINT FK_post_author
FOREIGN KEY (author_id
) REFERENCES tbl_user
(id
) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO tbl_post
(title
, content
, tags
, status
, update_time
, create_time
, author_id
) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6)
C:\xampp\htdocs\yii\framework\db\CDbCommand.php(354)
342 return $n;
343 }
344 catch(Exception $e)
345 {
346 if($this->_connection->enableProfiling)
347 Yii::endProfile(‘system.db.CDbCommand.execute(’.$this->getText().’)’,‘system.db.CDbCommand.execute’);
348 $errorInfo = $e instanceof PDOException ? $e->errorInfo : null;
349 $message = $e->getMessage();
350 Yii::log(Yii::t(‘yii’,‘CDbCommand::execute() failed: {error}. The SQL statement executed was: {sql}.’,
351 array(’{error}’=>$message, ‘{sql}’=>$this->getText().$par)),CLogger::LEVEL_ERROR,‘system.db.CDbCommand’);
352 if(YII_DEBUG)
353 $message .= '. The SQL statement executed was: '.$this->getText().$par;
354 throw new CDbException(Yii::t(‘yii’,‘CDbCommand failed to execute the SQL statement: {error}’,
355 array(’{error}’=>$message)),(int)$e->getCode(),$errorInfo);
356 }
357 }
358
359 /**
360 * Executes the SQL statement and returns query result.
361 * This method is for executing an SQL query that returns result set.
362 * @param array $params input parameters (name=>value) for the SQL execution. This is an alternative
363 * to {@link bindParam} and {@link bindValue}. If you have multiple input parameters, passing
364 * them in this way can improve the performance. Note that if you pass parameters in this way,
365 * you cannot bind parameters or values using {@link bindParam} or {@link bindValue}, and vice versa.
366 * binding methods and the input parameters this way can improve the performance.
Stack Trace
#0
- C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php(1014): CDbCommand->execute()
#1
- C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php(787): CActiveRecord->insert(null)
#2
– C:\xampp\htdocs\blog2\protected\controllers\PostController.php(67): CActiveRecord->save()
62 {
63 $model=new Post;
64 if(isset($_POST[‘Post’]))
65 {
66 $model->attributes=$_POST[‘Post’];
67 if($model->save())
68 $this->redirect(array(‘view’,‘id’=>$model->id));
69 }
70
71 $this->render(‘create’,array(
72 ‘model’=>$model,
#3
- C:\xampp\htdocs\yii\framework\web\actions\CInlineAction.php(50): PostController->actionCreate()
#4
- C:\xampp\htdocs\yii\framework\web\CController.php(309): CInlineAction->runWithParams(array())
#5
- C:\xampp\htdocs\yii\framework\web\filters\CFilterChain.php(134): CController->runAction(CInlineAction)
#6
- C:\xampp\htdocs\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()
#7
- C:\xampp\htdocs\yii\framework\web\CController.php(1146): CFilter->filter(CFilterChain)
#8
- C:\xampp\htdocs\yii\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(CFilterChain)
#9
- C:\xampp\htdocs\yii\framework\web\filters\CFilterChain.php(131): CInlineFilter->filter(CFilterChain)
#10
- C:\xampp\htdocs\yii\framework\web\CController.php(292): CFilterChain->run()
#11
- C:\xampp\htdocs\yii\framework\web\CController.php(266): CController->runActionWithFilters(CInlineAction, array("accessControl"))
#12
- C:\xampp\htdocs\yii\framework\web\CWebApplication.php(276): CController->run("create")
#13
- C:\xampp\htdocs\yii\framework\web\CWebApplication.php(135): CWebApplication->runController("post/create")
#14
- C:\xampp\htdocs\yii\framework\base\CApplication.php(162): CWebApplication->processRequest()
#15
– C:\xampp\htdocs\blog2\index.php(13): CApplication->run()
08 defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);
09 // specify how many levels of call stack should be shown in each log message
10 defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,5);
11
12 require_once($yii);
13 Yii::createWebApplication($config)->run();
2012-10-08 17:42:52 Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_p][/code]