Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create migration from existing database in laravel

I am new to laravel. 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.

like image 275
Hitesh Modha Avatar asked Jun 13 '14 08:06

Hitesh Modha


People also ask

How do I add a column in Laravel migration without losing data?

Show activity on this post. This way a new migration file will be created. Set your column details there, run the migrations using php artisan migrate and that's all. You'll have this new column in your users table without losing previously stored data.

What is Laravel database migration?

What is Laravel Migration? Laravel Migration is an essential feature in Laravel that allows you to create a table in your database. It allows you to modify and share the application's database schema. You can modify the table by adding a new column or deleting an existing column.


3 Answers

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:

  • https://github.com/adamkearsley/laravel-convert-migrations

  • https://github.com/barryvdh/laravel-migration-generator

Also, read the following answer in another question, might be useful to you or others: Reverse engineering or Auto-Generations of Entities in Laravel?

like image 133
nielsstampe Avatar answered Oct 26 '22 14:10

nielsstampe


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
like image 21
Joel Lim Avatar answered Oct 26 '22 15:10

Joel Lim


For modern versions of Laravel you should probably use a package like https://github.com/kitloong/laravel-migrations-generator

like image 40
Jeremy Belolo Avatar answered Oct 26 '22 15:10

Jeremy Belolo