Zerofill with Doctrine2


It looks like an easy task, but I can’t get it done:
How do I define a column to be UNSIGNED ZEROFILL with Doctrine2?

I can’t find any information about it in the docs.

Thx for any help!


Do you need it on database level or is it required only by the application? You could append zeros on the application level:

class MyEntity {
    public function getSomeColumn() {
        return sprintf('%05d', $this->someColumn); // or str_pad(...)

However if you really need it on database level then you’ll have to annotate the column as a string: @Column(type="string", columnDefinition="UNSIGNED INTEGER(5) ZEROFILL")

Answered By – Crozin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published