typeorm: Some schema changes not detected when generating migration

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [x] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [ ] @next [x] 0.2.22 (or put your version here)

Steps to reproduce or a small repository showing the problem:

Repo to reproduce: https://github.com/jalooc/typeorm-migration-generator-bug-repro

What happens: The linked repo is a minimal reproduction environment for the bug we’re having in a bigger project. What happens, is sometimes the migration generator doesn’t detect changes between database schema and entities. Note that it happens just sometimes - most of the time it works, so it’s rather not a problem of configuration. Sometimes doesn’t mean totally random in time, but rather random depending on particular change - if it doesn’t work for some change in entity, it won’t work no matter how many times I try; but it may work for a different change.

Steps to reproduce:

  1. Clone the above repository.
  2. Run migrations to initialise the database (there’s a utility script for that: npm run migrate-clean).
  3. Notice the additional bar field in the model (it was added after the initial migration had been generated).
  4. Run npx typeorm migration:generate -n second to generate the migration for the additional bar field. This yields:
No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command

but should generate a table altering script instead.

Note: you can also reproduce the steps checking out commits one by one.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 20 (3 by maintainers)

Most upvoted comments

just encountered probably the same issue on Postgres. I add a column to an existing entity and migration isn’t detecting changes.

This should be fixed in the next release. This can be confirmed in the latest dev build - 0.2.38-dev.22676a0

With 0.2.32 or less that’s work. From 0.2.33 or more that’s not working. Seem to be a difference between 0.2.32 and 0.2.33 version.

For me, this turned out to be caused by having a default database defined (in .env) that had the same name as the database that was specified in my entities (e.g. , { database: "name" }. This caused RdbmsSchemaBuilder.ts:661 to not be able to match database names.

MysqlQueryRunner.ts:2101 removes the database name from the table schema if it is the same as the default, but RdbmsSchemaBuilder.ts:661 always expects the database name to be there.

Removing the TYPEORM_DATABASE entry from .env fixed my issue.

I think MysqlQueryRunner should be modified to always add the database name, since I cannot think of a situation in which that will be problematic.

just encountered probably the same issue on Postgres. I add a column to an existing entity and migration isn’t detecting changes.

Just exactly same thing here

New observations: migrations stopped being generated at all with added db complexity. Seems that there’s something particular in models that blocks migration generator and once it appears in the codebase, they won’t be generated at all. I wasn’t able to track down what it is, will try to take a closer look at it and keep this thread updated in case of any findings.

I have the same problem. It’s work to create new tables but doesn’t work when adding columns. I use EntitySchema and 0.2.9 version

I would like to say that I have this exact same issue. Going back to an older version of TypeORM does not seem to help (at least up until v0.2.10)