SQL DDL to SQLAlchemy 2.0 Models

Converts CREATE TABLE statements into SQLAlchemy 2.0 declarative models using Mapped and mapped_column, covering column types, nullable, unique, primary keys, ForeignKey, server defaults and indexes.

Use the tool

Why this tool exists

SQLAlchemy 2.0 introduced the typed declarative style with Mapped[...] and mapped_column(), which is more verbose than the old Column syntax. Porting a schema by hand means choosing the right type for every column, working out Optional for nullable ones and writing constraints in __table_args__. Paste your DDL and this tool produces the classes: types, nullable, unique, primary keys, ForeignKey with ondelete, server defaults, UniqueConstraint and Index. It does not generate relationship() attributes, so you add those where you want object navigation. It is a quick way to start an ORM layer on an existing database. Everything is converted in your browser.

How to use it

  1. Paste your CREATE TABLE statements into the input box.
  2. Run the conversion to get the model classes.
  3. Copy them into your project, add relationship() attributes where needed and run your tests.

Frequently asked questions

Is this the 2.0 style?

Yes. The models use Mapped[...] type annotations together with mapped_column(), which is the typed style of SQLAlchemy 2.0, and not the older Column(...) declarations from earlier versions.

Are relationships generated?

No. Foreign keys are written as ForeignKey columns, but relationship() attributes are not created. Add them yourself based on how you use the models.

How are nullable columns typed?

They are annotated as Optional so type checkers know they can be None, and mapped_column is given nullable=True where needed.

How are defaults written?

Defaults found in the DDL are written as server defaults, so the database applies them. Python-side defaults need to be added by hand.