Unsigned Integer

For foreign key migrations instead of integer() use unsignedInteger() type or integer()->unsigned(), otherwise you may get SQL errors.

1Schema::create('employees', function (Blueprint $table) {
2 $table->unsignedInteger('company_id');
3 $table->foreign('company_id')->references('id')->on('companies');
4 // ...
5});

You can also use unsignedBigInteger() if that other column is bigInteger() type.

1Schema::create('employees', function (Blueprint $table) {
2 $table->unsignedBigInteger('company_id');
3});

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord