typeorm: Migrations are not detected after schema drop

Issue type:

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

Database system/driver:

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

TypeORM version:

[ ] latest [ ] @next [X] 0.3.0-alpha.22 (or put your version here)

Steps to reproduce or a small repository showing the problem: I have wanted to clean my database, so I have run : typeorm schema:drop then generate new migrations, but the cli has writen : No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command So I’ve tried to recreate my database, but the problem is still here module.exports = { "type": "postgres", "host": process.env.DATABASE_HOST || "localhost", "port": process.env.DATABASE_PORT || 5432, "username": process.env.DATABASE_USERNAME || "test", "password": process.env.DATABASE_PASSWORD || "test", "database": process.env.DATABASE_DATABASE || "syntrophi-test", "schema": process.env.DATABASE_SCHEMA || "public", "synchronize": false, "logging": true, "entities": [ "build/src/server/model/entities/**/*.js" ], "migrations": [ "build/src/server/model/migrations/**/*.js" ], "cli": { "entitiesDir": "src/server/model/entities", "migrationsDir": "src/server/model/migrations" } };

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

+1 I also just now ran into this after cloning my repo to the production server. Would be nice if the error message more clearly indicated that it simply couldn’t find any files at that path. Otherwise, it currently was a bit misleading as it seemed like it found files, but that the migration wasn’t needed. I can take a look at creating a PR to raise an exception/improve the message output if you don’t mind pointing me to the right place?

It would be clearer if the message said: ‘the migrations files are missing’ or ‘No migration files’. I remember when I’ve init a typeorm project, I’ve spent times figuring it out, I needed to first compile the migrations to run them

So I am really sorry, I’ve made a mistake in my ormconfig file, I was confused with my branches and the changes.

Thanks for your help.

You’re doing a great job with typeorm

I’m having similar issue. I add two relations to one of my entities and when I run migration:generate no changes were found.

Make shure that your ormconfig.json and the app.module.ts connection is the same. By that i mean like this:

=======My ormconfig.json=======

{
    "type": "mysql",      <==== THIS
    "host": "localhost", <==== THIS
    "port": 3306,           <==== THIS
    "username": "root", <==== THIS
    "password": "root", <==== THIS
    "database": "nest",  <==== THIS
    "entities": ["src/**/*.entity.ts"],
    "synchronize": false,
    "migrationsTableName": "migrations",
    "migrations": ["src/database/migrations/*.ts"],
    "cli": {
      "migrationsDir": "src/database/migrations"
    }
  }

=======My app.module.ts=======

  TypeOrmModule.forRoot({
    type: 'mysql',      <==== THIS
    host: 'localhost', <==== THIS
    port: 3306,          <==== THIS
    username: 'root', <==== THIS
    password: 'root', <==== THIS
    database: 'nest',  <==== THIS
    entities: ['dist/**/*.entity{.ts,.js}'],
    synchronize: false,
  }),

In case someone else ends up here because they’re getting a “No migrations are pending” message (despite there being new migrations), and the comments above don’t help, here’s what solved the problem for me.

I’ve never been able to get typeorm’s migration generation to work well for me, I created my recent migration file from another existing migration file.

The reason I wasn’t able to create a migration using that new file was that I had neglected to update the name of the migration class, and apparently typeorm uses the class name to decide if the migration already exists in your migrations table. Once I changed that class name in my new migration file, the migration worked as expected.

https://github.com/deweve/typeorm_issue

I’ve tried to recreate just a simple project with typeorm and I cannot generate any migrations