konekt / laravel-migration-compatibility
Library to help migrations to figure out whether a related field is int or bigInt
Installs: 123 408
Dependents: 8
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-pdo: *
- illuminate/database: ^10.0|^11.0
- konekt/enum: ^2.1 | ^3.0 | ^4.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
README
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 to solve 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.