在 Magento 设置脚本中添加 auto_increment 列,而不使用 SQL
之前我问过如何在不使用 SQL 的情况下在 Magento 设置脚本中更改表。在那里,Ivan 给出了一个很好的答案,我至今仍在参考。
但是我还没有发现如何使用 Varien_Db_Ddl_Table::addColumn()
来指定 auto_increment
列。我认为这与一个名为 identity
的选项有关,但到目前为止还没有运气。
这是否可能,或者该功能是否不完整?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
人们可以创建这样的自动增量列(至少从 Magento 1.6 开始,甚至更早):
除了“auto_increment”之外,还可以使用关键字“identity”。
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".
我认为这是尚未实施的事情。
如果您查看
addColumn
的源代码,您可以看到它查找identity/auto_increment
选项并在内部列上设置IDENTITY
属性表示。但是,如果您查看连接对象上的
createTable
方法,您可以看到
_getColumnsDefinition
、_getIndexesDefinition
和_getForeignKeysDefinition
用于创建CREATE SQL
片段。这些方法都没有引用identity
或auto_increment
,它们似乎也不会生成任何创建自动增量的sql。该类中唯一可能的候选者是
用于控制 PDO 绑定参数的增量数(与 auto_increment 无关)。
这里还提到了
auto_increment
,但它用于处理表上设置的选项。此
auto_increment
控制表AUTO_INCRMENT
选项,该选项可用于控制AUTO_INCRMENT
从哪个整数开始。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.