【问题标题】:Symfony 1.4 and doctrine autoincrement instead of auto_incrementSymfony 1.4 和学说 autoincrement 而不是 auto_increment
【发布时间】:2011-09-29 11:16:06
【问题描述】:

我有一个奇怪的问题。

这是我的 yaml:

Request: actAs: { Timestampable: ~ } columns: id: { type: integer(4), primary: true, autoincrement: true, notnull: true }

当我在我的BaseRequest.class.php 中执行 symfony doctrine:build --all --no-confirmation 时,我的 id 字段声明期间出现错误:

$this->hasColumn('id', 'integer', 4, array( 'type' => 'integer', 'primary' => true, 'autoincrement' => true, 'length' => 4, ));

如您所见,它应该是 auto_increment 但它是自动增量,所以我必须在每次构建后手动更改它。

有没有办法解决这个问题?

【问题讨论】:

  • 究竟是什么让你说它应该是auto_increment 而不是autoincrement?我的一个模型中有这个声明,autoincrement,在 MySQL 中,我可以看到 auto_increment,它工作正常。
  • 这在 mySQL 中很好,但是当我尝试保存我的项目时,我得到“无法获取最后一个插入标识符”,当我更改为 auto_increment 时它可以工作。
  • 插入新行后,mysql中SELECT LAST_INSERT_ID();返回什么?
  • 它返回 0,我不知道为什么。
  • 这两种情况你都试过了吗?有什么区别吗?另外,当你做SHOW CREATE TABLE your_table 时有什么不同吗?

标签: php symfony1 symfony-1.4 yaml


【解决方案1】:

不完全回答您的问题,但您不需要为您的实体指定 id 列,学说会自动执行此操作

【讨论】:

  • 是的,但我遇到了“无法获得最后一个插入标识符”的问题,所以我必须找到解决方法
猜你喜欢
  • 1970-01-01
  • 2012-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-11
相关资源
最近更新 更多