In this article we will go over on how we can create migration files from existing database in Laravel, I am working on a project which was converted from legacy PHP code into Laravel and no migration files were created in the process of conversion.

You might be in similar situation that you have your database tables ready, and you are now looking to take advantage of Laravel Database Migration system.

Here is how you can generate migration files from Existing Database in two simple steps.

We will be using Xethron/migrations-generator package for this.

Step 1: Install the Migrations-Generator package

First step is to install the migrations generator package. Open your Terminal / Command Line and navigate to the project root directory.

Run the following command.

composer require --dev "xethron/migrations-generator"

This will install the package in your project and will install the required dependencies.

Composer require xethron/migration-generator

Once the package is installed , we can go ahead to generate migration files.

Step 2: Generate Migration Files

Using this package is smooth and requires a single command to execute to convert all your database tables into migration files.

On the project root in your terminal, execute this artisan command

php artisan migrate:generate

This will convert all your tables into migration files. If you are looking to generate files for specific tables, you can use this command

php artisan migrate:generate table1,table2,table3,table4,table5

You can also choose to ignore few tables and generate all others by using the following command

php artisan migrate:generate --ignore="table3,table4,table5"

That's it ! The Migrations files will be created in your project in directory database > migrations .

Comments