0

After Deploy my laravel project to cloud (heroku) i noticed that when i trying to add new user or new role or new something .. the column id increment +10 .. for example the first user id = 1 , the second user id = 11

for example this is my roles table :

public function up()
{
    Schema::create('roles', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name')->unique();
        $table->timestamps();
    });
}

this is my roles table from mysql workbenck

Ersoy
  • 8,816
  • 6
  • 34
  • 48

1 Answers1

1

it is related to auto_increment_increment settings of mysql.

mysql> SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.04 sec)

Your auto_increment_increment is probably set to 10. you may set to 1 again via executing;

SET @@auto_increment_increment=1;

Please check here

Edit:

Since Heroku uses cleardb; it is not possible to change it while using cleardb. Here is the answer with the explanation

Ersoy
  • 8,816
  • 6
  • 34
  • 48
  • i try this but it still the same problem :/ – ilyés Tabessi May 17 '20 at 11:44
  • after setting, when you execute `SHOW VARIABLES LIKE 'auto_inc%';` if it is printing `1 and 1` - then you may refresh your migrations and seeds ? @ilyésTabessi – Ersoy May 17 '20 at 11:47
  • is printing 10 and 1 . the default value of auto_increment_increment in mysql = 10 but when i run SET @@auto_increment_increment=1; the result is "0 row(s) affected" – ilyés Tabessi May 17 '20 at 11:52
  • It is not updating then it is not reflecting but it is okay it to print 0 rows affected, i checked on my local env - https://prnt.sc/sidfwr - could you double check whether you are running the command it correctly @ilyésTabessi – Ersoy May 17 '20 at 12:22
  • could you share the similar screenshot to what i shared - setting and getting the value @ilyésTabessi – Ersoy May 17 '20 at 12:47
  • Sir , i'm runing the commande correctly the 'auto_increment_increment' changed to 1 link 1 : https://image.noelshack.com/fichiers/2020/20/7/1589719473-v1.png but after some minutes i run the same commande but the 'auto_increment_increment' returned to 10 link2: https://image.noelshack.com/fichiers/2020/20/7/1589719491-v2.png i think it is because some privileges of access or something like that . – ilyés Tabessi May 17 '20 at 12:50
  • i understand - probably some code, config or command is setting it back to 10 but i don't know who sets it back to 10, it may be related to your server, your code etc. Maybe you may search your project if there is any package, command, config has something ? @ilyésTabessi – Ersoy May 17 '20 at 12:53
  • @ilyésTabessi i searched some and found similar problem to yours; heroku is using cleardb as database - https://stackoverflow.com/a/38723706/2188922 please check here. i will update the answer too – Ersoy May 17 '20 at 12:57
  • yes i think the same , but in localhost it working fine i think the problem from the serve . any case big thanks for help sir :) – ilyés Tabessi May 17 '20 at 12:57
  • https://w2.cleardb.net/faqs/#general_16 here is the explanation - i updated the answer @ilyésTabessi - if it is okay for oyu, you may approve to help someone facing with the similar problem in the future. Have a good day – Ersoy May 17 '20 at 13:01
  • yes sir i see that , i will approuve inshallah . thanks :) – ilyés Tabessi May 17 '20 at 13:04