by default it's not posible, but maybe AUTO_INCREMENT is not reset after you delete some records in your database. so it's good to reset it by run ALTER TABLE countries AUTO_INCREMENT = 1; and then again run tinker and make new row.
please share here what you got.
Eloquent displays wrong random ID
When I'm trying to create a new record in DB, Eloquent displays wrong ID but it saves normal ID to database.
To show you an example, I've generated a new simple standard Laravel model "Country", so the table is completely new and empty. When I do this in Tinker:
app(Country::class)->create(['country' => 'Germany']), it returns this:
App\Models\Country {#6820
name: "Germany",
updated_at: "2025-01-06 04:29:02",
created_at: "2025-01-06 04:29:02",
id: 71558,
}
So, the problem is this ID 71558 which looks random. But ID in database is 1 as it supposed to be.
When I'm trying to create another model (like User) in Tinker, I get ID 71559 (the previous 71558 plus 1) but in database it's 22 as it supposed to be because I already have 21 users in the table.
So, it looks like Eloquent models show some ID which is common for all models and it's incrementing but it looks completely random. But then Eloquent saves normal ID to database.
I've never seen anything like this in any Laravel project. Do you guys have any idea why this is happening?
@webguy23 ah I think I understand. This query interfere with all others as pdo returns its $pdo->getInsertId() for all queries. You can try deferring the query to see if that helps
Please or to participate in this conversation.