Skip to content
gohacks.dev
Standard Library

SQL to Laravel Migration Converter

Turn CREATE TABLE statements from SHOW CREATE TABLE or mysqldump into a Laravel migration, with foreignId, timestamps, softDeletes and indexes recognised.

Free · No sign-up · Your inputs stay in your browser

Input

Convert CREATE TABLE to a Laravel migration

Output

Migration

1 table

Recognises Laravel's own conventions on the way back: id(), timestamps(), softDeletes(), rememberToken(), foreignId()->constrained() and the default index names, so a schema Laravel created round-trips to the migration that made it. CHECK constraints, generated columns and triggers have no Blueprint method and are skipped.

Runs in this browser. Nothing you paste is sent to a server.

When you need it

Adopting migrations on a database that was built by hand, porting a legacy application to Laravel, or turning a schema designed in a GUI tool into code. For a whole existing database, php artisan schema:dump is the official way to start from the current state; this is for the tables you want as readable, editable migrations. The migrations documentation lists every column type.

What does not convert

CHECK constraints, generated columns, triggers, partitioning and table options other than the engine have no Blueprint method, so they are left out. Add them with DB::statement() in the migration.

Share

Frequently asked questions

How do I get the CREATE TABLE statement for an existing table?
In MySQL, SHOW CREATE TABLE orders; prints it. For every table at once, mysqldump --no-data dbname. In PostgreSQL, pg_dump --schema-only --table=orders dbname.
Does it handle composite primary keys?
Yes. A PRIMARY KEY over several columns becomes $table->primary(['a', 'b']), and the columns are created without auto-increment.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools