In my form.php file I have added a field for an image to be inserted.

$fieldset->addField('main_image', 'image', array(
      'label'     => Mage::helper('blog')->__('Upload a Main Image'),
      'required'  => true,
      'name'      => 'main_image',

I'm not sure how to add this field to the database with my sql upgrade script?

So far I have this


$installer = $this;


$table = $installer->getConnection()
addColumn($installer->getTable('blog/blog'), 'main_image', array(
    'type'      =>


As you can see I didn't know what type to put it as, I've done a fair bit of googling and haven't found anything.

New to magento so thanks for the help :)


I would set it as VARCHAR(255) which is similar to other fields in Magento like the image field in catalog_category_flat_... tables. It should save the value of the relative path of your image in your media directory and be big enough to account for a variety of filenames.

Don't forget the -> before addColumn(

TIP: Remember that all the features in the Magento core are added in essentially the same way as any extension you write so it can often help to look at similar features in the modules in app/code/core/Mage/ to see how the Magento developers did it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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