【问题标题】:Doctrine Problem: Couldn't get last insert identifier原则问题:无法获得最后一个插入标识符
【发布时间】:2011-02-06 23:09:32
【问题描述】:

当我尝试将数据保存到我的模型时,Doctrine 抛出此异常:

Message: Couldn't get last insert identifier. 

我的表设置代码是:

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

请帮忙。谢谢。

【问题讨论】:

    标签: orm doctrine


    【解决方案1】:

    这对我有用:

    $this->hasColumn('cd_fabricante', 'integer', 4, array(
              'type' => 'integer',
              'length' => 4,
              'unsigned' => true,
              'primary' => true,
              'auto_increment' => true,
    ) );
    

    和你之前的参数一样,同样的错误。

    编辑:我最近发现在 PK 列定义中添加“auto_increment”,现在它的行为与 Doctrine 处理的任何给定 ID 字段相同,无论我选择什么名称

    【讨论】:

      【解决方案2】:

      检查以确保数据库中的列设置为 auto_increment。看起来 Doctrine 类将其作为 auto_increment 处理,但它并未在 DB 中设置。

      【讨论】:

      • 我希望我能多次支持这个。你刚刚让一个棘手的错误有 10 分钟的修复时间。
      【解决方案3】:

      对我来说,问题在于 default 参数。

              $this->hasColumn('inscription_id', 'integer', 4, array(
               'type' => 'integer',
               'length' => 4,
               'fixed' => false,
               'unsigned' => false,
               'primary' => true,
       //        'default' => '0', !!! get "couldn't get last inserted identifier doctrine"
               'notnull' => true,
               'autoincrement' => true,
               ));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-31
        • 2022-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多