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 1Short answer
migration:generate compares the entities your DataSource loads with the real database, and writes only the difference. No changes means that difference is empty: either the database already has your entity changes (often because synchronize ran), or the DataSource loads no entities, or it points at another database.
Fix it fast
1Find out which cause you have
Print which entities the DataSource loads and which database it connects to. Run it from a small script that imports the same DataSource file you pass to -d.
// check-ds.ts import dataSource from './src/data-source'; dataSource.initialize().then((ds) => { console.log(ds.options.database, ds.entityMetadatas.map((e) => e.name)); return ds.destroy(); });2Match what you see, then jump to its fix
- 1
The new column or table already exists in the database before you ran any migrationsynchronize already changed the databaseFix - 2
The first step prints an empty entity listThe DataSource passed to -d does not list your entitiesFix - 3
The database name printed by the first step is not the one your app usesThe CLI connects to a different database than you expectFix - 4
You edited a TypeScript class but not a decorator, column or relationThe entity change is not something a migration recordsFix
- 1
What does the error look like?
typeorm migration:generate finds no changes in the database schema, writes no file and exits with code 1
Cause 1 of 4
synchronize already changed the database
1Check
With synchronize: true, TypeORM updates the schema every time the app starts, so the database already matches the entities and nothing is left to generate.
grep -rn "synchronize" src2Fix
Turn synchronize off, as the migrations guide requires. To get a migration for the change that was already applied, point the DataSource at a database that does not have it yet (for example a fresh copy of production) and generate again.
export default new DataSource({
// ...connection options
synchronize: false,
migrations: ['src/migrations/*.ts'],
});3Verify
Generate against a database that still has the old schema. A migration file is written.
npm run typeorm migration:generate -- -d src/data-source.ts src/migrations/AddColumnConfirmed by typeorm.io
Cause 2 of 4
The DataSource passed to -d does not list your entities
1Check
The entities option takes entity classes or paths and globs. An empty or wrong path loads nothing, so there is nothing to compare.
grep -n "entities" src/data-source.ts2Fix
List the entity classes or a glob that matches your entity files. Use a glob that also matches the file type the CLI runs (TypeScript with ts-node, JavaScript after a build).
entities: ['src/**/*.entity.ts'],3Verify
Run the first-step script again: the entity names appear.
npx ts-node check-ds.tsConfirmed by typeorm.io
Cause 3 of 4
The CLI connects to a different database than you expect
1Check
The DataSource file used by the CLI often has its own connection settings, separate from the Nest app, and may read a different environment file.
grep -n "database\|host\|url" src/data-source.ts2Fix
Read the same environment variables in both places, or build both configs from one shared object.
// src/data-source.ts
import 'dotenv/config';
export default new DataSource({
type: 'postgres',
url: process.env.DATABASE_URL,
entities: ['src/**/*.entity.ts'],
synchronize: false,
});3Verify
The first-step script prints the database your app uses.
npx ts-node check-ds.tsConfirmed by typeorm.io
Cause 4 of 4
The entity change is not something a migration records
1Check
Only changes in the schema are detected. Changing a method, a type that is not a column, or code outside the entity does not alter the database.
git diff -- '*.entity.ts'2Fix
Add or change the column, relation or index decorator you meant to. If you need a data change or custom SQL, create an empty migration and write it yourself.
npm run typeorm migration:create src/migrations/BackfillData3Verify
Generate again after the decorator change.
npm run typeorm migration:generate -- -d src/data-source.ts src/migrations/ChangeConfirmed by typeorm.io
How do I stop it coming back?
- Keep synchronize: false everywhere once you use migrations.
- Use one DataSource file for the CLI and import it into the Nest module config.
- Add a package.json script "typeorm": "typeorm-ts-node-commonjs" (or typeorm-ts-node-esm) so the CLI can read TypeScript entities.
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
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 connects but creates no tables or columns
A new column is missing, with no error at startup
TypeORM does not create tables by itself.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 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
NestJS GraphQL cannot work out the output type of a field or query
Cannot determine a GraphQL output type for the "<name>". Make sure your class is decorated with an appropriate decorator.
In code-first mode Nest reads TypeScript types through decorators, and arrays, promises and unions disappear at runtime.
2 causes, each with a fix