Kishore
Kishore

Reputation: 352

Laravel - Cockroach DB - Auto increment is generating UUID

I am creating new migration With Laravel 5.8 and cockroachDB. I am trying with increments to generate auto increment column in laravel migration. But it is generating UUID instead of sequence. Can any one having idea please help me on this. please check my migration.

Schema::create('billing_organisations_test1', function (Blueprint $table) {
            $table->increments('id');     //bigIncrements also not working
            $table->string('name');
            $table->timestamps(6);
            $table->softDeletes('deleted_at', 6)->default(null);
        });

Laravel migration is generating the below query . How to set id column default value as auto increment.

CREATE TABLE billing_organisations_test1 (  
id INT8 NOT NULL DEFAULT unique_rowid(),
    name VARCHAR(255) NOT NULL,
    created_at TIMESTAMP NULL,
    updated_at TIMESTAMP NULL,
    deleted_at TIMESTAMP NULL,
    CONSTRAINT "primary" PRIMARY KEY (id ASC),
    FAMILY "primary" (id, name, created_at, updated_at, deleted_at)
)

Upvotes: 3

Views: 544

Answers (2)

rafiss
rafiss

Reputation: 583

You need to set the serial_normalization setting to sql_sequence. Just be aware that this can decrease performance. Does the app really require incrementing IDs?

See: https://www.cockroachlabs.com/docs/stable/serial.html#modes-of-operation

Upvotes: 1

Hayato
Hayato

Reputation: 56

Try this one below your code.

DB::statement("ALTER TABLE table_name AUTO_INCREMENT = 0;");

Upvotes: 0

Related Questions