SQL to Sequelize Models
Paste one or more SQL CREATE TABLE statements and get ready-to-use Sequelize model definitions back. The converter maps every standard SQL column type to the right DataTypes.*, carries over NOT NULL, PRIMARY KEY, UNIQUE, AUTO_INCREMENT/SERIAL, and DEFAULT values so your models reflect the real schema without manual retyping.
How to use the SQL to Sequelize Models
Paste your CREATE TABLE DDL into the input box — multiple tables separated by semicolons are supported. Click Generate Models (or press Example to load a demo) and the output area fills with sequelize.define() calls, one per table.
- Paste DDL — supports MySQL and Postgres syntax, including
IF NOT EXISTSand backtick/double-quote identifiers. - Review output — each column is represented as an attribute object with
type,allowNull,primaryKey,autoIncrement,unique, anddefaultValuewhere applicable. - Copy — paste directly into your Sequelize project. Add
const { Sequelize, DataTypes } = require('sequelize');and asequelizeconnection at the top of the file.
Foreign key columns are emitted as plain INTEGER/BIGINT attributes. To add the actual association call User.hasMany(Post, { foreignKey: 'user_id' }) separately after model definition — that is the Sequelize idiomatic approach.
What is Sequelize and why generate models from SQL?
Sequelize is a promise-based ORM for Node.js that supports PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server. Every table you want to query through Sequelize must have a corresponding model — a JavaScript object that describes the table's columns, their data types, and constraints. Writing these models by hand from an existing schema is tedious and error-prone: a single mismatched type or a missing allowNull: false can cause subtle validation failures or incorrect generated queries.
The canonical Sequelize pattern uses sequelize.define('ModelName', attributes, options) where attributes is a map of column names to descriptor objects and options carries settings like tableName, timestamps, and underscored. SQL types map to DataTypes members: INT → DataTypes.INTEGER, VARCHAR(n) → DataTypes.STRING(n), TEXT → DataTypes.TEXT, BOOLEAN → DataTypes.BOOLEAN, TIMESTAMP → DataTypes.DATE, DECIMAL(p,s) → DataTypes.DECIMAL(p,s), JSON/JSONB → DataTypes.JSON, and UUID → DataTypes.UUID.
This tool automates that mechanical translation. It is especially useful when inheriting a legacy database, working database-first rather than code-first, or syncing models after a migration adds new columns. It does not replace Sequelize Migrations — for schema changes in production always use queryInterface migrations — but it gives you a correct model baseline to work from.
Common use cases
- Legacy database adoption — inherit an existing MySQL or Postgres schema and need Sequelize models without writing each one by hand.
- Database-first development — your team keeps the SQL schema as the source of truth and generates application code from it.
- Model synchronization after migrations — a DBA adds columns; regenerate models instead of hunting down every attribute to update.
- Onboarding documentation — generated models serve as readable, typed documentation of a schema for new developers joining the project.
- Multi-dialect projects — the same DDL runs on MySQL and Postgres; the converter produces Sequelize models that work on both without change.