What should I do if yii2 fails to save update data?
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses best practices for deploying Yii applications in cloud-native environments, focusing on scalability, reliability, and efficiency through containerization, orchestration, and security measures.

The article discusses key considerations for using Yii in serverless architectures, focusing on statelessness, cold starts, function size, database interactions, security, and monitoring. It also covers optimization strategies and potential integrati

The article discusses tools for monitoring and profiling Yii application performance, including Yii Debug Toolbar, Blackfire, New Relic, Xdebug, and APM solutions like Datadog and Dynatrace.

The article discusses strategies for testing Yii applications using Codeception, focusing on using built-in modules, BDD, different test types, mocking, CI integration, and code coverage.

Yii's built-in testing framework enhances application testing with features like PHPUnit integration, fixture management, and support for various test types, improving code quality and development practices.

The article discusses implementing real-time data synchronization using Yii and WebSockets, covering setup, integration, and best practices for performance and security.

The article discusses Yii's benefits for SaaS development, focusing on performance, security, and rapid development features to enhance scalability and reduce time-to-market.

The article discusses key considerations for deploying Yii applications in production, focusing on environment setup, configuration management, performance optimization, security, logging, monitoring, deployment strategies, and backup/recovery plans.
