Previously I asked how to ALTER TABLE in Magento setup script without using SQL. There, Ivan gave an excellent answer which I still refer to even now.
However I have yet to discover how to use Varien_Db_Ddl_Table::addColumn()
to specify an auto_increment
column. I think it has something to do with an option called identity
but so far have had no luck.
Is this even possible or is that functionality incomplete?
I think that's something that hasn't been implemented yet.
If you look at the source to
addColumn
, you can see it looks for aidentity/auto_increment
option and sets anIDENTITY
attribute on the internal column representation.However, if you look at the
createTable
method on the connection objectyou can see
_getColumnsDefinition
,_getIndexesDefinition
, and_getForeignKeysDefinition
are used to create aCREATE SQL
fragment. None of these methods make any reference toidentity
orauto_increment
, nor do they appear to generate any sql that would create an auto increment.The only possible candidates in this class are
which is used to control the increment number for a PDO bound parameter (nothing to do with
auto_increment
).There's also a mention of
auto_increment
herebut this is used to process options set on the table. This
auto_increment
controls the tableAUTO_INCREMENT
options, which can be used to control which integer anAUTO_INCREMENT
starts at.One can create an autoincrement column like that (at least since Magento 1.6, maybe even earlier):
Instead of "auto_increment", one may also use the keyword "identity".