I have a magento site with many custom options. When the product is created, sometimes the sku is longer than 255 characters.

The sku I'm refering to is in "sales_flat_order_item" and a few other places I believe.

Is it safe to change these fields to "text" instead of "varchar255"?


If you run the following query against the database you can find all of the tables which have an sku column:


You will find the following returned:

catalog_product_entity - varchar(64)
catalog_product_flat_1 - varchar(64)
catalog_product_flat_2 - varchar(64)
catalog_product_flat_x // as many flat tables as there are stores
catalog_product_option - varchar(64)
catalog_product_option_type_value - varchar(64)
sales_flat_creditmemo_item - varchar(255)
sales_flat_invoice_item - varchar(255)
sales_flat_order_item - varchar(255)
sales_flat_quote_address_item - varchar(255)
sales_flat_quote_item - varchar(255)
sales_flat_shipment_item - varchar(255)

So a fair few tables. Although making the sku field longer is not something I have tried, I don't see any particular reason why it won't work, but you should approach the task carefully with plenty of testing.

No idea why but it seems sku is stored as a 64 character long field in relation to products, and a 255 character long field in relation to ordered items - so you are essentially restricted to 64 characters by default.

My advice would be to write an install script to change these columns, something along the lines of the following:

$installer = $this;

        'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
        'length' => '64k',
        'comment' => 'SKU'

// more changeColumn() calls for each table


A few gotcha's I would look out for:

  • There may be some PHP based restrictions on the length of content saved to these fields, have to test to be sure
  • Watch out if you upgrade the store, some of these columns could be reset to 64/255 characters and data will irrecoverably be lost in the process if this is the case
  • Be careful when adding new stores as a new flat product table will be created so you will need to check the field is of the correct length.
  • Yea, I think I only need to worry about the varchar(255) ones. The varchar(64) are for simple products, meaning the acutal product sku. My sku gets built on the fly when making a product. It's dynamic, and is sometimes over 255 characters. So I think changing the SKU's in the "sales_flat" tables should be good enough.
    – Switch
    Nov 24 '14 at 16:53

Yes it is. Magento doesn't do any checks on this afaik. So if it is longer than 255, mysql doesn'T raise an error and just cuts this (f*cking mysql)

so, just write an install script to change this and you won'T have problems in the future, as long as the sku is shorter than TEXT length (16 mio?)

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.