Answer the question
In order to leave comments, you need to log in
Why doesn't the standard Update CRUD method work?
/**
* Updates an existing news model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
return $this->redirect(['view', 'id' => $model->id]);
Database Exception – yii\db\Exception
SQLSTATE[HY000]: General error: 1364 Field 'caption' doesn't have a default value
The SQL being executed was: INSERT INTO `ab_news` (`id`) VALUES (DEFAULT)
Error Info: Array
(
[0] => HY000
[1] => 1364
[2] => Field 'caption' doesn't have a default value
)
↵
Caused by: PDOException
SQLSTATE[HY000]: General error: 1364 Field 'caption' doesn't have a default value
in W:\domains\localhost1\vendor\yiisoft\yii2\db\Command.php at line 1290
Answer the question
In order to leave comments, you need to log in
For a model, specify rules with its fields.
Turn on the debug mode, it helps a lot to understand where there is no data.
Pay attention to the request in the error, it contains only the id field.
General error: 1364 Field 'caption' doesn't have a default value
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question