How do you use a BIGINT as an Auto-Incrementing Primary Key in Laravel 4

后端 未结 2 1095
小蘑菇
小蘑菇 2020-12-20 16:08

I am trying to mimic wordpress\' primary key size which is BIGINT(20) but it seems that laravel doesn\'t have a native function to do this.. I saw a page in the laravel foru

2条回答
  •  一向
    一向 (楼主)
    2020-12-20 16:43

    When using bigInteger() also applying it to foreign key in some table, make sure you connect it properly with unsignedBigInteger(),

    public function up()
    {
            Schema::create('create_this_table_after_users', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->unsignedBigInteger('user_id');
               // Other Columns
            });
            Schema::table('create_this_table_after_users', function($table) {
                $table->foreign('user_id')->references('id')->on('users');
                // Other Constraints 
            });
    }
    

    Reference Link of the Laravel 4.2 Doc

提交回复
热议问题