nafiesl / SimpleCrudGenerator

Faster test-driven development for CRUD feature in Laravel project.
https://packagist.org/packages/luthfi/simple-crud-generator
MIT License
170 stars 51 forks source link

[BUG] Foreign key constraint error after artisan migrate on Laravel 5.8 #13

Closed nafiesl closed 5 years ago

nafiesl commented 5 years ago

A facebook friend named Adhik Mulat, inform that he got following error (foreign key constraint) when on artisan migrate command after generate a model CRUD.

simple-crud-error-laravel-5 8

This happened because in laravel 5.8 the default users table migration uses bigIncrement data type on id column. But in generated migration file (like image below) the foreign user_id colum still using integer (not big integer).

Laravel 5.8 users table migration file

photo_2019-03-09_15-06-08

Generated migration file

photo_2019-03-09_15-05-52

nafiesl commented 5 years ago

To solve this problem, we need to change the migration file stub. https://github.com/nafiesl/SimpleCrudGenerator/blob/948247c2fbf479328f8e2fd135225b4a2fe2a04b/src/stubs/database/migrations/migration-create.stub#L20

This line need to changed into

$table->unsignedBigInteger('creator_id'); 
nafiesl commented 5 years ago

Resolved with this commit e445fc866cee6b6761450d40254bafbc1dafb07f.