0

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.

3
  • Welcome to SO ... "I tried several ...", tried several what? would you like to provide what you tried Commented Sep 1, 2020 at 8:36
  • Not natively, maybe there is a package. Commented 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. Commented Sep 1, 2020 at 9:58

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

Comments

0

you can use below command to migrate each table separately.

php artisan migrate --path=/database/migrations/migrationnamefull.php

it will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.