TypeORM connects but creates no tables or columns
No tables appear in the database after the app startsShort answer
TypeORM does not create tables by itself. Either synchronize is on, or migrations run. Check that one of them is configured, that your entities are registered, and that initialize() was called and awaited before the first query. Do not leave synchronize on in production.
Fix it fast
1Find out which cause you have
Print how the DataSource is set up: whether schema sync or auto-run migrations are on, and which entities it loaded.
await AppDataSource.initialize() console.log(AppDataSource.options.synchronize, AppDataSource.options.migrationsRun) console.log(AppDataSource.entityMetadatas.length)2Match what you see, then jump to its fix
What does the error look like?
No tables appear in the database after the app startsA new column is missing, with no error at startup
Cause 1 of 3
Neither synchronize nor migrations are doing the work
1Check
The docs define synchronize as auto-creating the schema on every launch, and migrationsRun as running migrations on every launch. Both default to off.
grep -n -E "synchronize|migrationsRun" src/data-source.ts2Fix
For local work set synchronize to true. For anything shared, turn it off and run migrations instead.
// local development only
synchronize: true,
// everywhere else
synchronize: false,
migrationsRun: true,3Verify
Restart and list the tables.
psql "$DATABASE_URL" -c '\dt'Confirmed by typeorm.io
Cause 2 of 3
The entities are not registered, so there is nothing to create
1Check
Synchronize builds the schema from the registered entities. With a glob that matches no files, it has nothing to build and says nothing.
grep -n "entities" src/data-source.ts2Fix
Register the classes, or use a glob with both extensions based on __dirname.
entities: [__dirname + "/entities/**/*{.ts,.js}"],3Verify
The first-step print shows a non-zero count and the tables appear.
psql "$DATABASE_URL" -c '\dt'Confirmed by typeorm.io
Cause 3 of 3
initialize() was never called, or not awaited
1Check
The docs say you must call initialize once to open the connection, and that database access is only possible after setup.
grep -rn "initialize()" src2Fix
Call initialize at startup and wait for it before the server starts listening.
await AppDataSource.initialize()
app.listen(3000)3Verify
The app logs the connection before it accepts requests.
curl -i http://127.0.0.1:3000/healthConfirmed by typeorm.io
How do I stop it coming back?
- Use synchronize only on a throwaway local database.
- Generate a migration for every entity change and commit it.
- Log the loaded entity count and the migration count at startup.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
TypeORM cannot find an entity, or the metadata for a relation
Entity metadata for Role#users was not found.
TypeORM only knows the entities listed in the entities option of the DataSource that is running.
2 causes, each with a fixBack end
Node.js in Docker Compose cannot reach MySQL on 127.0.0.1:3306
Error: connect ECONNREFUSED 127.0.0.1:3306
Inside a container, 127.0.0.1 is that container, not MySQL.
3 causes, each with a fixBack end
Knex runs out of connections and the query waits until it times out
Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
Every query needs a free connection from Knex's pool.
3 causes, each with a fixBack end
PostgreSQL error: bind message has N parameter formats but 0 parameters
QueryFailedError: bind message has N parameter formats but 0 parameters
One query is carrying more bound values than the Postgres protocol can describe.
2 causes, each with a fixBack end
TypeORM sync fails when a new column is NOT NULL on an existing table
QueryFailedError: column "price" contains null values
TypeORM columns are NOT NULL by default.
3 causes, each with a fixBack end
TypeORM migration:generate finds no changes to put in the migration
typeorm migration:generate finds no changes in the database schema, writes no file and exits with code 1
migration:generate compares the entities your DataSource loads with the real database, and writes only the difference.
4 causes, each with a fix