Is there a way to create migrations from an existing database in Laravel 7. I tried several but they are not working with Laraval 7.
-
Welcome to SO ... "I tried several ...", tried several what? would you like to provide what you triedlagbox– lagbox2020-09-01 08:36:20 +00:00Commented Sep 1, 2020 at 8:36
-
Not natively, maybe there is a package.Jerodev– Jerodev2020-09-01 08:37:24 +00:00Commented Sep 1, 2020 at 8:37
-
There was a way for Laravel 5 laravel-news.com/… You could give it a shot for L7. Assuming your project is of medium size, you could be better off by creating the migrations manually. Respect the natural order of the table hierarchy (foreign keys) and you'll be fine.Dimitri Mostrey– Dimitri Mostrey2020-09-01 09:58:37 +00:00Commented Sep 1, 2020 at 9:58
2 Answers
Yes, you can generate migrations from an existing database in Laravel. Open source laravel packages have made it easier to do so.
For Laravel 7 Kitloong's Laravel migration generator is the best match for creating migrations from an existing database.
This is the github package -> https://github.com/kitloong/laravel-migrations-generator
In very basic and simple steps you will get the things you need. You just need to install the package.
composer require --dev "kitloong/laravel-migrations-generator"
After installation run :
php artisan migrate:generate
If you want to generate migrations for specific table :-
php artisan migrate:generate table1,table2,...,table_n
If you want to ignore some tables :
php artisan migrate:generate --ignore="table3,table4"
For full documentation you can visit -> https://github.com/kitloong/laravel-migrations-generator
Thanks to Kitloong's Laravel Migration Generator.