Laravel migration (errno: 150 “Foreign key constraint is incorrectly formed”)

Since increments() creates an unsigned integer column, you need to define the foreign key column as unsigned integer too. Default migrations in Laravel 6+ use bigIncrements(), so you need to use unsignedBigInteger() method: $table->unsignedBigInteger(‘order_id’); https://laravel.com/docs/6.x/migrations#foreign-key-constraints For default migrations in older versions of Laravel use unsignedInteger() method: $table->unsignedInteger(‘order_id’); Or: $table->integer(‘order_id’)->unsigned(); https://laravel.com/docs/5.5/migrations#foreign-key-constraints

php artisan migrate:make create_mytable fails: “migrate:make” is not defined

The syntax has changed to php artisan make:migration. Here are the available make commands. make:auth Create auth classes for the application make:console Create a new Artisan command make:controller Create a new resource controller class make:filter Create a new route filter class make:migration Create a new migration file make:provider Create a new service provider class make:request … Read more

Safely remove migration In Laravel

I accidentally created a migration with a bad name (command: php artisan migrate:make). I did not run (php artisan migrate) the migration, so I decided to remove it. My steps: Manually delete the migration file under app/database/migrations/my_migration_file_name.php Reset the composer autoload files: composer dump-autoload Relax If you did run the migration (php artisan migrate), you … Read more