We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Models default value problem


I have a database that has a table products it has fields id, name, img the id is autoicrement, name is varchar and img is tinyint 1 char (default: 0) this is used to show if an image exists (1 and 0). The generated model in phalcon shows the img field is structured as:

     * @var integer
     * @Column(column="img", type="integer", length=1, nullable=false)
    public $img;

When I run an insert:

$product = new Products();
$product->name =  $this->request->getPost('name');

and output the errors, I get the following:

We can't store product right now: img is required

What is the best way to overcome this, I was relying the database to do most of the workload, as I have created a lot of tales with default value.



Oopps, I think I found it I will give it a try and report back:


By default models works with notNullValidations making all columns "not null" required. Check this

Good luck