I have an Admin Grid with one column named min_weight. This column has the datatype decimal (5,2) in the database. The default value for the column is NULL. If I try to save an entry with the Admin form, Magento always fills the empty column with 0.00. But I would like to have the value NULL in the database not 0.00. Is there a way to stop Magento 2 from formatting the column value as 0.00?

This is the field configuration in the form.xml:

<field name="min_weight" formElement="input">
 <argument name="data" xsi:type="array">
  <item name="config" xsi:type="array">
   <item name="source" xsi:type="string">zones</item>
  <label translate="true">Min. Weight</label>
   <rule name="required-entry" xsi:type="boolean">false</rule>

The form data that is submitted when pressing the save button contains an empty value for this attribute (which is correct):

items[985][name]: test

But Magento 2 writes this empty value with 0.00 in the database.

The problem exists regardless of whether I modify the record via inline editing or on the Edit page, or create a new record.

I would be very thankful for any advice!

  • Do you have the definition of min_weight in your database? Probably you must set your column as nullable="true", and with defaul value null Apr 20 at 14:58
  • 1
    In my database the min_weight column is of the type decimal(5,2) with nullable true and default value NULL. If I add a new entry to my table via phpMyAdmin the min_weight column is correctly saves as NULL. So I guess that the issue is related to the way magento 2 saves the entry.
    – Luisa
    Apr 21 at 7:40


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.