<i id='rFCAP'><tr id='rFCAP'><dt id='rFCAP'><q id='rFCAP'><span id='rFCAP'><b id='rFCAP'><form id='rFCAP'><ins id='rFCAP'></ins><ul id='rFCAP'></ul><sub id='rFCAP'></sub></form><legend id='rFCAP'></legend><bdo id='rFCAP'><pre id='rFCAP'><center id='rFCAP'></center></pre></bdo></b><th id='rFCAP'></th></span></q></dt></tr></i><div id='rFCAP'><tfoot id='rFCAP'></tfoot><dl id='rFCAP'><fieldset id='rFCAP'></fieldset></dl></div>

      <small id='rFCAP'></small><noframes id='rFCAP'>

      <legend id='rFCAP'><style id='rFCAP'><dir id='rFCAP'><q id='rFCAP'></q></dir></style></legend>

      <tfoot id='rFCAP'></tfoot>
          <bdo id='rFCAP'></bdo><ul id='rFCAP'></ul>
      1. 如何禁用 Laravel eloquent Auto Increment?

        时间:2023-09-23
            <bdo id='5jCce'></bdo><ul id='5jCce'></ul>

              <i id='5jCce'><tr id='5jCce'><dt id='5jCce'><q id='5jCce'><span id='5jCce'><b id='5jCce'><form id='5jCce'><ins id='5jCce'></ins><ul id='5jCce'></ul><sub id='5jCce'></sub></form><legend id='5jCce'></legend><bdo id='5jCce'><pre id='5jCce'><center id='5jCce'></center></pre></bdo></b><th id='5jCce'></th></span></q></dt></tr></i><div id='5jCce'><tfoot id='5jCce'></tfoot><dl id='5jCce'><fieldset id='5jCce'></fieldset></dl></div>
            1. <small id='5jCce'></small><noframes id='5jCce'>

              <tfoot id='5jCce'></tfoot>

                    <tbody id='5jCce'></tbody>
                • <legend id='5jCce'><style id='5jCce'><dir id='5jCce'><q id='5jCce'></q></dir></style></legend>

                • 本文介绍了如何禁用 Laravel eloquent Auto Increment?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要一种有效的方法来禁止 Laravel 自动识别我要插入数据的表的主键.

                  I need an effective way to disable Laravel from auto incriminating the primary key of the table which I am going to insert data in.

                  为什么?我不检查数据库和插入的数据之间是否有任何重复,所以如果有任何重复,我只是在 try-catch 块中处理它.

                  Why? I don't check if there is any duplication between the DB and the inserted data so if there was any duplication I just handles it in a try-catch block.

                  问题是如果有任何失败,Laravel 会像我插入一行一样计数.所以 IDs 列不会按照这个顺序 [1, 2, 3, etc],而是按照这个 [1, 4, 8, 20, etc].

                  The problem is if there was any failure Laravel counts it like I have inserted a row. So IDs column is not going to be in this order [1, 2, 3, etc], but in this [1, 4, 8, 20, etc].

                  我搜索了很多关于这个问题,我尝试在类声明后使用这一行:

                  I searched a lot about this issue and I have tried to use this line after the declaration of the class:

                  public $autoincrement = false;
                  

                  还有

                  public $incrementing = false;
                  

                  但它们不起作用.

                  我只想使用我的数据库的 AI.不是 Laravel 的.

                  推荐答案

                  抱歉,大家耽误了您的时间,问题是,如果我们尝试在 MYSQL 中保存任何记录,无论它因任何原因返回成功还是失败(例如在我的情况下重复),

                  Sorry for taking your time guys, The issue is if we tried to save any record in MYSQL whether it returned success or failure for any reason (like for duplication in my case),

                  MYSQL 计算自动增量编号已被预订,并且任何其他即将到来的记录都不会占用它,因为可能同时在 DB 上有多个插入过程并等待知道自动增量编号是否为预订与否都会降低 MYSQL 的速度.

                  MYSQL counts that the auto increment number was booked and any other coming record is not going to take it because of there may be more than an insertion process on the DB in the same time and waiting to know if the auto incrementally number is booked or not will cost MYSQL its speed.

                  所以这不是 Laravel 的问题,而是 MYSQL 的问题.

                  So it is not a Laravel issue, its a MYSQL one.

                  我希望它可以帮助其他人.

                  I hope that it may help others.

                  谢谢大家...

                  这篇关于如何禁用 Laravel eloquent Auto Increment?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:合并和排序两个 Eloquent 集合? 下一篇:Laravel 使用 Eloquent 的多对多关系

                  相关文章

                  最新文章

                        <bdo id='L33jb'></bdo><ul id='L33jb'></ul>
                    1. <tfoot id='L33jb'></tfoot>
                    2. <i id='L33jb'><tr id='L33jb'><dt id='L33jb'><q id='L33jb'><span id='L33jb'><b id='L33jb'><form id='L33jb'><ins id='L33jb'></ins><ul id='L33jb'></ul><sub id='L33jb'></sub></form><legend id='L33jb'></legend><bdo id='L33jb'><pre id='L33jb'><center id='L33jb'></center></pre></bdo></b><th id='L33jb'></th></span></q></dt></tr></i><div id='L33jb'><tfoot id='L33jb'></tfoot><dl id='L33jb'><fieldset id='L33jb'></fieldset></dl></div>

                      <small id='L33jb'></small><noframes id='L33jb'>

                    3. <legend id='L33jb'><style id='L33jb'><dir id='L33jb'><q id='L33jb'></q></dir></style></legend>