magento add new column to database changes in files

magento add new column to database changes in files

October 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento add new column to database changes in files

Adding a New Column to an Existing Magento Table

When you want to add a new column to an existing Magento table, it’s not just about running the SQL query in your database. You also need to make changes to the core Magento code files to ensure the new column is recognized and used correctly within the application.

Let me guide you through the process of adding a verified_in column to the sales_flat_order table in Magento 1.5.1 with MySQL 5.

Step 1: Create the Database Column

Open your MySQL database using a client like phpMyAdmin or MySQL Workbench.

Create a new column named verified_in in the sales_flat_order table:

ALTER TABLE sales_flat_order
ADD verified_in VARCHAR(32) NOT NULL DEFAULT '';

This adds a new nullable (but not really, because of NOT NULL) column called verified_in with a default value of an empty string. The data type is set to VARCHAR(32) as you specified.

Step 2: Update the EAV Model

Magento uses an Entity-Attribute-Value (EAV) model for many of its database tables, including sales_flat_order. To make sure Magento can handle this new attribute, you need to update the corresponding XML file.

Open your favorite text editor and navigate to:

app/code/core/Mage/Sales/etc/config.xml

Find the <entities> node under <sales>, which looks like this:

<entities>
    <order>
        <table>sales_flat_order</table>
        <attributes>
            <!-- Existing attributes here -->
        </attributes>
    </order>
</entities>

Add a new attribute for verified_in:

<entity name="order">
    <table>sales_flat_order</table>
    <attributes>
        <!-- Existing attributes here -->
        <verified_in>
            <input class="validate-code validate-length maximum-length-32"/>
            <backend_model>Mage_Eav_Model_Backend_Sales_Item</backend_model>
        </verified_in>
    </attributes>
</entity>

This tells Magento to use the Mage_Eav_Model_Backend_Sales_Item model for the verified_in attribute, which is a standard backend model for order-related attributes in Magento.

Step 3: Update the Form and Interface

Next, you need to update your admin interface to display this new field on the sales order view page. Open:

app/design/adminhtml/default/default/template/sales/order/view/tab/details.phtml

Find the line that starts the details block:

<block type="core/multi_field" name="order_details">
    <action method="setData"><name>items</name><value>$items</value></action>
    <label>Order Details</label>

Immediately after this, add a new field for verified_in:

<block type="adminhtml/sales_order_item" name="order_details_verified_in">
    <fieldsets>
        <fieldset>
            <fieldsets>
                <general>
                    <column class="input-label">
                        <label>Verified In</label>
                    </column>
                    <column class="input-column">
                        <text field="verified_in"/>
                    </column>
                </general>
            </fieldsets>
        </fieldset>
    </fieldsets>
</block>

This adds a new Verified In column to the order details tab in your admin interface.

Conclusion

Adding a new column to an existing Magento table involves more than just running a SQL query—you need to update core files and interfaces as well. By following these steps, you’ve successfully added a verified_in column to the sales_flat_order table and made sure it’s recognized by your Magento application.

Remember, when working with core files in Magento, always back up your data first. If you’re unsure about any part of this process, consider reaching out to our professional Magento development services for expert assistance.

Happy coding!

Magento 1 Database Admin Configuration

Our network