大型自动增量编号 [英] Large Auto Increment IDs

查看:61
本文介绍了大型自动增量编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在桌子上有一些自动入账ID时遇到了一个奇怪的问题,它似乎不是每次都增加1,而是每次都增加10.

I'm having a strange issue with some auto-inc IDs on a table, where instead of going up by 1 each time, it seems to be going up by 10 each time.

我正在使用

  • 用于Heroku的ClearDB MySQL插件
  • PHP 5.5.15
  • Apache 2.4.10
  • Laravel开发分支(4.something)

我已经通过artisan的迁移功能创建了数据库,我对数据库表的迁移是

I've created the database via artisan's migrate functionality, My migration for the database table is

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCheckinTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('checkins', function(Blueprint $table)
        {
            $table->increments('id');

            $table->integer('visitor_id');
            $table->integer('meeting_id');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('checkins');
    }

}

但是,当我通过此创建新条目时

However when Im creating a new entry via this

    $this->checkin = new Checkin;
    $this->checkin->visitor_id = $this->id;
    $this->checkin->meeting_id = $this->nextMeetingId();
    $this->checkin->save();

Checkin类看起来像

The Checkin Class looks like

<?php

class Checkin extends Eloquent {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'checkins';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('updated_at', 'visitor_id');

    protected $fillable = array();

    public function meeting(){
        return $this->hasOne('Meeting','id', 'meeting_id');
    }

    public function client(){
        return $this->hasOne('Visitor','id','visitor_id');
    }

}

但是在添加和添加多个条目之后,数据库表现在看起来像

However after F5ing and adding multiple entries the database table now looks like

id  visitor_id meeting_id updated_at created_at

1   1   0   2014-08-04 21:25:25 2014-08-04 21:25:25
11  1   0   2014-08-04 21:35:54 2014-08-04 21:35:54
21  1   0   2014-08-04 21:35:57 2014-08-04 21:35:57
31  1   0   2014-08-04 21:35:59 2014-08-04 21:35:59
41  1   0   2014-08-04 21:36:01 2014-08-04 21:36:01
51  1   0   2014-08-04 21:36:03 2014-08-04 21:36:03

您可以看到ID每次增加10而不是1.

As you can see the id's is going up by 10 each time rather than 1.

所以如果有人知道原因,请告诉我:)

So if anybody knows the reason for this, please update me :)

非常感谢

推荐答案

作为其他遇到此问题的人的答案.

As an answer for others experiencing this issue.

之所以采取较大措施,是因为ClearDB实施了MySQL配置.

The reason for the big steps was due to a MySQL Configuration that ClearDB had implimented.

此处列出了执行此操作的原因: http://www.cleardb.com /developers/help/faq#general_16 (感谢Razor)

Their reasoning for doing this is listed here: http://www.cleardb.com/developers/help/faq#general_16 (Thanks Razor for this)

如果您需要自己调查增量设置,则可以运行以下查询

If you need to investigate your increment settings yourself you can run the following query

SHOW VARIABLES LIKE 'auto_inc%';

这将输出类似

auto_increment_increment    10
auto_increment_offset   1

所以您可以看到我跳的原因是因为它被设置为10.

So you can see the reason for my jumps was because this was set to 10.

如@Juergen d所述,如果需要 通过以下查询,您应该可以更改此设置.

As @Juergen d said you should be able to change this if you need to by the following queries.

SET @@auto_increment_increment=1
SET GLOBAL auto_increment_increment=1;

但是我没有更改此设置,因为ClearDB设置了它是有原因的,并且我只是在查询它以防万一我配置错误.

I however didnt change this setting as ClearDB set it for a reason, and I was only querying this incase it was something i had mis-configured.

关闭案例,感谢大家的投入.

Case Closed, Thanks to everybody for their input.

这篇关于大型自动增量编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆