Skip to content
Compatibility Helper for Integer vs. BigInteger Problem in Laravel Migrations
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src
tests
.gitignore
.styleci.yml
.travis.yml
Changelog.md
LICENSE.md
README.md
composer.json
phpunit.xml.dist

README.md

Laravel Migration Compatibility

Travis Build Status Packagist Stable Version Packagist downloads StyleCI MIT Software License

Laravel 5.8 And The BigInt Problem

As of Laravel 5.8, migration stubs use the bigIncrements method on ID columns by default. Previously, ID columns were created using the increments method.

Foreign key columns must be of the same type. Therefore, a column created using the increments method can not reference a column created using the bigIncrements method.

This small change is a big source of problems for packages that define references to the default Laravel user table.

This package helps solving this problem by extending Laravel's Blueprint class by a method that can detect the actual referenced field type:

class CreateProfilesTable extends Migration
{
    public function up()
    {
        Schema::create('profiles', function (Blueprint $table) {
            $table->increments('id');

            // Make `user_id` field the same type as the `id` field of the `user` table:
            $table->intOrBigIntBasedOnRelated('user_id', Schema::connection(null), 'users.id');

            //...

            $table->foreign('user_id')
                ->references('id')
                ->on('users');
        });
    }
//...

Installation

composer require konekt/laravel-migration-compatibility

Documentation

For detailed usage and examples go to the Documentation or refer to the markdown files in the docs/ folder of this repo.

For the list of changes read the Changelog.

You can’t perform that action at this time.