Php

I have a weird problem I don't understand: I have a command to import data.

I have a weird problem I don't understand: I have a command to import data. The relevant section looks like this
 
Gallery::truncate();
DB::table('galleries_old')->get()->each(function ($gallery) {
$new_gal = Gallery::create([
'name' => $gallery->name,
'date' => $gallery->date,
'description' => $gallery->description,
]);

});

 
 at the end of the command I output `$this->info(Gallery::count());` and it shows `26` which is the same number of rows as in the old table. Next I open tinker do the same and it shows: `0`. Still in tinker I add a row:
 
=> App\Models\Gallery {#3346
name: "adsf",
date: "1990-01-01 00:00:00",
description: "asdf",
slug: "adsf-1",
updated_at: "2019-03-17 21:32:11",
created_at: "2019-03-17 21:32:11",
id: 27,
}

 
note: *id=27*. I open the table in a viewer and it shows 1 record with id=27. What tf happend to the 26 records I imported?
You already invited:

TimDaub

Upvotes from:

No caching? No transactions?
And what does a MySQL (SELECT COUNT(*) FROM WOTEVA) show?
[I wonder if `Galery::count()` is proxying to a stale object]
Do `$it = new Gallery(); dump($it->toSql()); dump($it->count());`

MarcoFalke

Upvotes from:

The dump you imported from had this statement `SET AUTOCOMMIT = 0;` - removing it solved it. Never used this statement so  you didnt notice it earlier  in case you're interested.

If you wanna answer this question please Login or Register