Is there any way to generate Migrations based on an existing database in Laravel?

Asked

Viewed 318 times

2

When I used Python’s Django, I was surprised by the command inspectdb, that is able to generate models based on an existing database.

At Laravel, we have Migrations to work with the database, and I find a very clean and organized way to keep changes to a project’s database.

However, in Laravel, by default, Migrations are always created manually, and usually the tutorials I see always indicate that they should be used from the beginning of the project development.

I did, however, have a new need: I have a database dump and would like to turn it into Laravel Migrations.

Is there a library in Laravel that allows reverse engineering of a database, transforming it into Laravel’s own Migrations?

That is, I want a library to read the existing database and manage the Migrations based on that structure.

I would like an answer to that, if possible, for Laravel 4 and 5 (as I use the 4 still).

Observing: I wouldn’t like solutions like importing DUMP to Migration and running it. It’s not ideal for the case I need.

1 answer

2

There is a library called Migrations Generator which reads an existing database and generates the migrations correspondents and she even supports the Laravel 4.

I did a simple test using Laravel 5.6, with the bank on Mariadb and it correctly generated all the columns of each table, only that there is a porem. I realized that relationships were not generated.

Anyway, it’s worth looking at and testing.

  • I used one that reads relationships.

  • I did a thorough search for what I realized it generated the relationships only in a separate file. Anyway, this library is a good option. Which one did you use ?

  • Ah, interesting. I had used a barryvdh/migration-generator, but I realized that xethron/migrations-generator answered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.