Tinabot
Tinabot

Reputation: 429

Laravel tinyInteger primary key with incrementation

I am trying to add via script primary keys and I have variables which says if it's primary key and if it is inc. The problem is that I can't find a way to easily define the primary key that increments.

With this migration Laravel only adds primary key, but it isn't inremented:

$table->tinyInteger('taxable')->primary();

this only added primary key without incrementation


$table->tinyInteger('taxable')->primary()->increments();

Didn't add auto-inc.


$table->tinyInteger('taxable', true);

Tried this method which instantly applies primary key and auto-inc, but I want it to be flexible for my script. (I don't want that it would add primary key and auto-inc both instantly I want to define it myself).

So I tried different variations but none of them gave me the result I wanted - to easily define if it is a primary key and if it is auto-incremented.

  $table->tinyInteger('taxable', true, true);
  $table->tinyInteger('taxable', false, true);
  $table->tinyInteger('taxable', true, false);
  $table->tinyInteger('taxable', false, false);

It seems that the second false doesn't do anything at all and I thought the first true - defines if it is primary key and the second true if it is auto-incremented.


I found the best solution for me (because I wanted to find an easy way to define primary keys in my script):

$table->tinyInteger('taxable')->autoIncrement(); //Adds primary key and auto-inc
$table->tinyInteger('taxable')->primary(); //adds just primary key

Upvotes: 1

Views: 985

Answers (1)

Darryl E. Clarke
Darryl E. Clarke

Reputation: 7647

there's a special increments method in migrations:

$table->tinyIncrements('id');

Upvotes: 1

Related Questions