簡體   English   中英

Laravel 5.8 Eloquent Create() 返回錯誤的 Id

[英]Laravel 5.8 Eloquent Create() return wrong Id

public function up() {
        Schema::create( 'active_stocks', function ( Blueprint $table ) {
            $table->bigIncrements( 'id' );
            $table->string( 'sku' );
            $table->text( 'title' )->nullable()->default( '' );
            $table->integer( 'cost' )->default(0);
            $table->integer( 'qty' )->default(0);
            $table->string( 'stock_tracking' )->default('')->nullable();
            $table->integer( 'type' )->default(1);
            $table->text( 'image' )->nullable();
            $table->integer( 'user_id' );
            $table->integer( 'status' )->default(1);
            $table->timestamps();
        } );
        \Illuminate\Support\Facades\DB::statement( "ALTER TABLE `active_stocks` AUTO_INCREMENT = 9999999999;" );
    }

我已將自動增量設置為我在開發中想要的某個值。 然后我使用 Laravel Eloquent 創建一個新記錄

$create = App/ActiveStock::create(
 [
    'sku'            => $item_array['sku'],
    'qty'            => $item_array['qty'],
    'stock_tracking' => $item_array['tracking'],
    'type'           => ActiveStock::TYPE_IMPORTED,
    'cost'           => $item_array['cost'],
    'user_id'        => $user_id,
 ]
)

echo $create->id; //Should be 9999999999

但我得到了這個2147483647但我查看了數據庫,id 值為9999999999 ,這是正確的。

我在這里缺少什么。

這是 $create 的完整回復

App\ActiveStock Object
(
    [fillable:protected] => Array
        (
            [0] => sku
            [1] => title
            [2] => cost
            [3] => qty
            [4] => stock_tracking
            [5] => type
            [6] => image
            [7] => user_id
            [8] => status
        )

    [connection:protected] => mysql
    [table:protected] => active_stocks
    [primaryKey:protected] => id
    [keyType:protected] => int
    [incrementing] => 1
    [with:protected] => Array
        (
        )

    [withCount:protected] => Array
        (
        )

    [perPage:protected] => 15
    [exists] => 1
    [wasRecentlyCreated] => 1
    [attributes:protected] => Array
        (
            [sku] => test-B00MSOIUOO
            [qty] => 11
            [stock_tracking] => 
            [type] => 1
            [cost] => 112
            [user_id] => 1
            [updated_at] => 2020-02-08 17:12:38
            [created_at] => 2020-02-08 17:12:38
            [id] => 2147483647
        )

    [original:protected] => Array
        (
            [sku] => test-B00MSOIUOO
            [qty] => 11
            [stock_tracking] => 
            [type] => 1
            [cost] => 112
            [user_id] => 1
            [updated_at] => 2020-02-08 17:12:38
            [created_at] => 2020-02-08 17:12:38
            [id] => 2147483647
        )

    [changes:protected] => Array
        (
        )

    [casts:protected] => Array
        (
        )

    [dates:protected] => Array
        (
        )

    [dateFormat:protected] => 
    [appends:protected] => Array
        (
        )

    [dispatchesEvents:protected] => Array
        (
        )

    [observables:protected] => Array
        (
        )

    [relations:protected] => Array
        (
        )

    [touches:protected] => Array
        (
        )

    [timestamps] => 1
    [hidden:protected] => Array
        (
        )

    [visible:protected] => Array
        (
        )

    [guarded:protected] => Array
        (
            [0] => *
        )

)

2147483647 是 32 位有符號整數的最大值。 您可能正在使用 32 位版本的 PHP。

您訪問的數字太大。 214748364732-bit int的最大限制。
如果您想存儲和使用比這更大的數字,您可能需要將列類型從int更改為類似varchar(100)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM