I need to add a new column/field (total_volume) to sales_shipment table. I know that I can use two approaches to do this, but what is the best?

The first approach is to use the "Extension Attributes". In this way Magento generate for me the methods getVolume and setVolume.

The second approach is to use the "Declarative Schema". The problem is that with this approach Magento doesn't generate for me the methods getVolume and setVolume. I should use the magic methods (that I don't like too much). To do what I want, I think that with this approach I should extend the ShipmentInterface and create a subclass for Shipment Model. Is it right?

So between these two approaches, what should I use? When should I use the first and when the second approach?

2 Answers 2


I found some helpful articles about "Extension Attributes" and this is what I understood:

  • "Declarative Schema" is used when you need to create a NEW table inside Magento. With declarative schema you have the advantages of mutations.
  • "Extension Attributes" are used to add new fields inside an EXISTING table. In this way you don't extend the original model.

So in the above example, the best approach is to use Extension Attributes. magento-2-what-are-extension-attributes


Since shipment is also an eav attribute, another option to add a new column to the sales_shipment table is via SchemaPatchInterface

public function apply()
    $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
            'type' => 'varchar',

Perform bin/magento setup:upgrade to install the schema patch

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.