I need to add a text attribute to placed orders, filled by logic in a observer module. Now I used/follow this code before on Magento 2.2 and there it worked like expected. Now, copying the same module to Magento 2.3 doesn't seem to fire the installData at all (I added logging to check, never comes up in the logs), so the required database columns aren't created, thus my order-process is now broken.

Now I've seen and read this about declarative schema, that the installData is being phased out, but I also understand that it should still work in 2.3, and I haven't the time to rewrite the module.

My installData contents are now this (this is the code that worked in 2.2 but not 2.3)

namespace DC\OrderAttributes\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Sales\Model\Order;

class InstallData implements InstallDataInterface
     * @var \Magento\Sales\Setup\SalesSetupFactory
    protected $salesSetupFactory;

     * @param \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory
    public function __construct(
        \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory
    ) {
        $this->salesSetupFactory = $salesSetupFactory;

     * {@inheritDoc}
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) 
        $installer = $setup;


        $salesSetup = $this->salesSetupFactory->create(['resourceName' => 'sales_setup', 'setup' => $installer]);

        $salesSetup->addAttribute(Order::ENTITY, 'dc_order', [
            'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            'length'=> 255,
            'visible' => false,
            'nullable' => true

                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 255,
                'comment' =>'Order to dc'


Can anybody help me figure out why these tables aren't created? I've uninstalled/removed the module and the corresponding row in setup_module in the database to trigger the install each time; no success.

1 Answer 1


your code is fine: I have run it on Magento 2.3.3 and the attributes are created correctly. My guess is your module is installed into your system and therefore you'd need to add the sql into an UpgradeData script for instance?

to see whether your module is part of your Magento 2.3.3 system, you may go to your setup_module: `select * from setup_module where module='DC_OrderAttributes';

More simply, php bin/magento module:status should list your module

To remove your module, you can physically delete from setup_module the row mentioning your module. (please backup your system if this is the option you choose). Then flush your cache to reinstall the module

The most recommended way is to use the UpgradeData rather than InstallData

  • Right.. This is good news in some way. But I don't understand why it won't work on my install then; I deleted the row from setup_module, disabled the mod via CLI, ran all the setup/compile commands etc multiple times and it just won't fire.. I'll try it with UpgradeData then, see what happens.. Thanks so far!
    – Asitis
    Nov 18, 2019 at 22:14
  • of course, setting up x-debug will go a long way for you not to have to guess the issue Nov 19, 2019 at 9:33
  • Sure, but I've spent way more hours trying to setup x-debug and not able to get it working either :P
    – Asitis
    Nov 19, 2019 at 9:35
  • Well completely removed the module again, added the update data script, still nothing. I'm losing my mind I think.
    – Asitis
    Nov 19, 2019 at 10:36
  • try php bin/magento cac:cle, php bin/magento set:upg and if nothing, check browser console error, server logs.. It can be a nasty hunt but ultimately, it seems your system has an error somewhere Nov 19, 2019 at 10:37

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.