In the Phalcon framework, when the native SQL statement is used for update operations, a problem occurs: when the content of a field in the database to be operated is blank, the UPDATE will fail? What's going on? Can anyone help me? In the Phalcon framework, when using native SQL statements for update operations,
A problem occurs:
When the content of a field in the database to be operated is null, an error occurs during UPDATE?
What's going on? Can anyone help me?
Reply content:
In the Phalcon framework, when using native SQL statements for update operations,
A problem occurs:
When the content of a field in the database to be operated is null, an error occurs during UPDATE?
What's going on? Can anyone help me?
In this case, the Phalcon ORM will enable several features by default. One of the notNullValidations features is to check whether the field is Not null, so when you do Not fill in the corresponding field, an exception will be thrown.
There are two solutions: Modify the database, and disable this feature. Of course, you can also write the code that automatically complements the default value in the program logic. generally, setting NotNull for a field must be justified. Therefore, it is recommended that the logic of the program be robust, rather than making up for coding errors in other ways.
Document link: 1
Provide the relevant code for reference:
php
public function skipValidation($skipers=[]) { foreach ($skipers as $skiper) { if (empty($this->$skiper)) { $this->$skiper = new \Phalcon\Db\RawValue('""'); } } }
When using:
php
public function beforeValidation(){ ...... $this->skipValidation(['tag','source_url']); ......}