yii2 The solution to the failure of saving updated data: first find and open the original script file that caused the error; then add validation rules for the new field in Rules in the model class, or set the field to "safe".
YII2 failed to update data
Cause:
CLI mode, scheduled task. Synchronize DB data in other systems through views.
Recommended: "yii Tutorial"
Process:
The original script has been written, and it has been modified based on the existing ones and added new fields. .
After adding the field, it was executed, but it was always unsuccessful. The utime recorded in the table could also be updated successfully, but only the newly added field failed to be updated.
Try to print the $model->validate() result with no problem. $model->save() also returns true. $model->errors() returns empty. All is fine.
Suddenly remembered that the newly added fields were not added in the model class, so I changed it to $model->save(false) to turn off verification. Still unsuccessful.
Solution:
Add validation rules for new fields to Rules in the model class, or set the field to safe.
Summary:
What a cheat. Save(false) used to be OK, but this time it doesn’t work. .
The analysis should be a syntax problem. This time the data assignment method is
$info->attributes = $data;
The above is the detailed content of What should I do if yii2 fails to save update data?. For more information, please follow other related articles on the PHP Chinese website!