Replies: 7 comments 18 replies
-
You mean: $table->bigInteger('column')->autoIncrement(); ? |
Beta Was this translation helpful? Give feedback.
-
Yes there is no Schema method for making auto-increment without primary key. But i used this migration with pgsql: public function up()
{
Schema::create('foos', function(Blueprint $table) {
$table->bigInteger('id')->unsigned()->index();
...
});
DB::statement('CREATE SEQUENCE foos_id_seq START 1 owned by foos.id;');
DB::statement('ALTER TABLE foos ALTER COLUMN id SET DEFAULT nextval(\'foos_id_seq\'::regclass)');
} |
Beta Was this translation helpful? Give feedback.
-
I agree with this. It would be good if we can create auto incrementing columns without setting them as primary key. In our case we need an auto incrementing order number which will be used in the Invoices. But we don't want to use this order number as primary key. Because we are using a standard UUID column as primary key in all the tables. |
Beta Was this translation helpful? Give feedback.
-
Would it affect the performance if I update it in the
|
Beta Was this translation helpful? Give feedback.
-
Fixed on Laravel 11.x #49925 |
Beta Was this translation helpful? Give feedback.
-
Hi, I was looking for a way to achieve this in my migrations.
|
Beta Was this translation helpful? Give feedback.
-
Another possible solution (works with singlestore) Blueprint::macro('autoBigIncrementOnly', function (string $column) {
/**
* @var \Illuminate\Database\Schema\Blueprint $this
*/
return $this->addColumn('autoBigIncrementOnly', $column)->index();
});
SingleStoreSchemaGrammar::macro('typeAutoBigIncrementOnly', function () {
return 'BIGINT UNSIGNED AUTO_INCREMENT';
}); $table->autoBigIncrementOnly('id'); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a need to create an auto-incrementing column which is not to be used as the primary key of the table. There are methods like
$table->bigIncrements('id')
which create auto-increment columns, but they also assume the column as the primary key.It seems like it would be ideal to separate the primary key concerns from these methods so the developer can make that choice. For instance, by using the
->primary()
method:Though, I guess at this point it would be a breaking change to do that. Perhaps the solution would be to create new methods specific to non-primary key use?
Beta Was this translation helpful? Give feedback.
All reactions