Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I import a mysql dump to a laravel migration?

Tags:

laravel

I have a complete database and need to create migration. I guess there must be a way to do it from a dump but not sure. Is there any way automatically or at least easier to do this task?

like image 672
vladzur Avatar asked Jan 23 '14 11:01

vladzur


People also ask

Does Laravel support MySQL?

Currently Laravel supports four database systems: MySQL, Postgres, SQLite, and SQL Server.

What methods are used in Laravel for migration?

A migration class contains two methods: up and down . The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.


2 Answers

You can import dumps in Laravel like this:

DB::unprepared(file_get_contents('full/path/to/dump.sql')); 

If I were to refactor an existing app, though, I'd take the time to write migrations from scratch, import the dump into different tables (or a different db, if table names are the same) then import the content to the new structure via seeds.

like image 105
Tomas Buteler Avatar answered Sep 27 '22 19:09

Tomas Buteler


Laravel can't do that, but I think this will help: Laravel migration generator

It generate migrations based on existing tables.

like image 29
Kevin Gorjan Avatar answered Sep 27 '22 20:09

Kevin Gorjan