SQL to Laravel Migration Converter

Paste one or more CREATE TABLE statements and get Laravel migration files you can drop into database/migrations. Foreign keys become foreignId()->constrained(), created_at/updated_at become timestamps().

FreeNo sign-upRuns in your browser: your data is not uploaded

When this converter saves you time

You usually need it in one of three situations. You inherited an old PHP project with a database but no migrations. You designed the tables in phpMyAdmin or MySQL Workbench first and now want them in Laravel. Or a client sent you a .sql dump and you want the schema under version control before you touch anything.

Writing those migrations by hand is slow and easy to get wrong: a missed unsigned on a foreign key column is enough to make php artisan migrate fail with errno: 150 "Foreign key constraint is incorrectly formed".

How to get the CREATE TABLE statement

  • phpMyAdmin: open the table, go to Export, choose Custom, untick "Data" and keep "Structure". Copy the result.
  • MySQL / MariaDB command line: SHOW CREATE TABLE users; prints the exact statement.
  • Whole database: mysqldump --no-data -u root -p shop > schema.sql, then paste the file here. The tool picks up every CREATE TABLE and ignores the rest.

What the converter maps, and how

MySQLLaravel migration
bigint unsigned AUTO_INCREMENT named id$table->id()
int AUTO_INCREMENT$table->increments('id')
tinyint(1)boolean(), with default(false) for DEFAULT '0'
varchar(191)string('email', 191) (length left out when it is 255)
enum('a','b')enum('status', ['a', 'b'])
decimal(10,2)decimal('total', 10, 2)
created_at + updated_attimestamps()
deleted_atsoftDeletes()
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADEforeignId('user_id')->constrained()->cascadeOnDelete()
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPuseCurrent()->useCurrentOnUpdate()

Anything without a direct Blueprint method (for example MONEY from another database) is written as a string() column with a comment and listed above the code, so you can fix that one line yourself instead of finding out at migrate time.

File order matters with foreign keys

Laravel runs migrations by file name. If orders runs before users, the foreign key has nothing to point to and the migration stops. The converter sorts the files so referenced tables come first and gives them timestamps one second apart, in that order. Keep those names when you save the files.

Check the result before you run it

  1. Save each file in database/migrations.
  2. On a copy of the database (never production first), run php artisan migrate:fresh.
  3. Compare with the original: SHOW CREATE TABLE orders; on both. Column order and index names may differ; types, nullability and keys should match.

If the existing production tables are already there and you only want Laravel to "know" about them, do not run these migrations on that database. Insert their names into the migrations table instead, so Laravel treats them as already run.

FAQ

Does this upload my database schema anywhere?
No. The conversion runs in JavaScript inside your browser tab. Nothing is sent to HeadsNTail or any other server, so it is safe to paste a client's schema.
Which Laravel versions does the output work with?
The files use the anonymous-class migration style (return new class extends Migration), which works in Laravel 9, 10, 11 and 12. For Laravel 8 or older, give the class a name and remove return new class.
Why did UNSIGNED disappear from my decimal column?
Recent Laravel versions no longer offer unsignedDecimal(), and MySQL 8.0.17 deprecated UNSIGNED for DECIMAL columns. The tool writes a plain decimal() and tells you so. Add validation in your code if negative values must be blocked.
Can it convert a whole mysqldump file?
Yes. Paste the full dump. Comments, INSERT statements and settings lines are ignored; every CREATE TABLE becomes its own migration file.
What about PostgreSQL?
Common PostgreSQL types (serial, text, jsonb, uuid, bytea, timestamp default now()) are understood. The tool is tested mostly with MySQL and MariaDB output, so check PostgreSQL results a little more carefully.

Related guides

Found it useful? Put a link in your docs, README or forum answer so others can use it too:

HTML
<a href="https://headsntail.com/tools/sql-to-laravel-migration">SQL to Laravel Migration Converter</a> (free, by HeadsNTail)
Markdown (GitHub, Stack Overflow, dev.to)
[SQL to Laravel Migration Converter](https://headsntail.com/tools/sql-to-laravel-migration)

Need it done on your server? HeadsNTail sets up Laravel apps, cPanel hosting and migrations for businesses. See services or ask a question.