Reputation: 2790
I know command to create database from laravel
migration.
I have already created database in mysql
. so how can i convert migration from that database?
Upvotes: 23
Views: 44238
Reputation: 358
If the accepted answer (at the time of editing this post) does not work for you, use this simple approach.
Check out this package by Kitloong is really easy to use.
https://github.com/kitloong/laravel-migrations-generator
After installation, just run something like this to export the migration to a location of your choice:
php artisan migrate:generate --path="path\to\existing\folder"
Example:
php artisan migrate:generate --path="C:\xampp\htdocs\laravel_bs4\database\migrations\my_new_migrations"
You should end up with migrations created from the database and saved in the location you have specified.
You can omit the --path
option and simply run
php artisan migrate:generate
This would export it to the default Laravel's migration folder (which is something I usually do not want).
Be sure to follow the prompts. Sticking to the default is usually okay.
Upvotes: 5
Reputation: 4541
For modern versions of Laravel you should probably use a package like https://github.com/kitloong/laravel-migrations-generator
Upvotes: 7
Reputation: 61
How about this?
Migrations Generator.It's for Laravel, 4, 5, 6, 7, but I don't know if it is for Laravel 8
Upvotes: 2
Reputation: 7891
If you don't mind using Doctrine 2 in your project instead of Eloquent that has reverse engineering built in.
Upvotes: 1
Reputation: 979
Simple solution, to use online Laravel migration generator for your existing SQL table schema without installing any package. Just enter your SQL schema and get Laravel migration file. Try: https://laravelarticle.com/laravel-migration-generator-online
Upvotes: 2
Reputation: 1364
You could use Jeffrey Way's generator tool for Laravel 4, and do them by hand. It is a very useful tool. https://github.com/JeffreyWay/Laravel-4-Generators (if you are using Laravel 5, use this package instead: https://github.com/laracasts/Laravel-5-Generators-Extended)
Or you could try out one of the following packages, they should convert your existing schema to Laravel migrations. I have not tried them, but have a look:
Also, read the following answer in another question, might be useful to you or others: Reverse engineering or Auto-Generations of Entities in Laravel?
Upvotes: 18
Reputation: 67
I quick wrote this python script to make migration files out of an existing database.
https://github.com/aljorhythm/sql-to-laravel-migrations
After set up, just do
python retrieve-and-convert.py
Upvotes: 4