question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

migrations doesnt run even after doing everything

See original GitHub issue

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

I am working on a project with typeorm on nestjs. the problem is even after running mgration after generating migration files, i get No migrations are pending

The commands i am using are

 "typeorm": "NODE_ENV=dev ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/config/typeorm.config.ts",
 
"typeorm:migrate": "npm run typeorm migration:generate -- -n",
 
"typeorm:run": "npm run typeorm migration:run"

I am doing

npm run typeorm:migrate test
npm run typeorm:run

BTW: my ormconfig looks like this


import config from '@config/index';
import { join } from 'path';
import { ConnectionOptions } from 'typeorm';

const typeormConfig: ConnectionOptions = {
  type: 'postgres',
  host: config.db.host,
  port: config.db.port,
  logging: ['error'],
  username: config.db.username,
  password: config.db.password,
  database: config.db.database,
  entities: [join(__dirname, '../entities/**{.ts,.js}')],
  synchronize: false,
  migrations: ['migrations/**/*{.ts,.js}'],
  cli: {
    migrationsDir: 'migration',
  },
};

export = typeormConfig;


Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:33 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
danieldspxcommented, Jun 2, 2020

This No migrations are pending means that somewhere in the migration table it says that you have already run the migration for your migration file. Follow this steps:

  1. If you are using nestjs: Delete your dist folder (Just to make sure you dont get an Duplicated migration error).
  2. Delete everything in the migrationtable.
  3. Run the migration again

Hope this solves you problem.

7reactions
hbthegreatcommented, Mar 21, 2020

This is what I am using as the ormconfig.ts

import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';

interface BetterConnectionOptions extends PostgresConnectionOptions {
  readonly seeds?: (Function | string)[];
  readonly factories?: (Function | string)[];
}

const config: BetterConnectionOptions = {
  type: 'postgres',
  host: 'localhost',
  port: 5432,
  username: 'dbusernamegoeshere',
  password: 'changeme',
  database: 'dbnamegoeshere',
  entities: [__dirname + '/entities/**/*.entity{.ts,.js}'],
  synchronize: false,
  migrationsRun: false,
  logging: true,
  logger: 'file',
  migrations: [__dirname + '/migrations/**/*{.ts,.js}'],
  seeds: ['src/database/seeds/**/*.seed.ts'],
  factories: ['src/database/factories/**/*.factory.ts'],
  cli: {
    migrationsDir: 'src/migrations',
  },
};

export = config;

From this we started using dotenv as well for configuration with a file kinda like this:

import * as dotenv from 'dotenv';
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
import * as dbindex from 'database-index';
dotenv.load('./../.env');
interface BetterConnectionOptions extends PostgresConnectionOptions {
  readonly seeds?: Function | string[];
  readonly factories?: Function | string[];
}
const dirName = __dirname;
const config: BetterConnectionOptions = {
  cli: {
    migrationsDir: dirName + '/migration',
  },
  database: process.env.mpDatabaseDatabase,
  entities: dbindex.entities,
  factories: process.env.mpDatabaseFactories.split('|'),
  host: process.env.mpDatabaseHost,
  logger: process.env.mpDatabaseLogger as any,
  logging: process.env.mpDatabaseLogging === 'true',
  migrations: dbindex.migrations,
  migrationsRun: process.env.mpDatabaseMigrationsRun === 'true',
  password: process.env.mpDatabasePassword,
  port: parseInt(process.env.mpDatabasePort),
  seeds: process.env.mpDatabaseSeeds.split('|'),
  synchronize: process.env.mpDatabaseSynchronize === 'true',
  type: process.env.mpDatabaseType as any,
  username: process.env.mpDatabaseUsername,
};

export = config;

One tip that isn’t immediately obvious if you are using dotenv and use any of the typeorm default env variables like these:

TYPEORM_HOST = localhost
TYPEORM_USERNAME = root
TYPEORM_PASSWORD = admin
TYPEORM_PORT = 3000
TYPEORM_LOGGING = true

The cli will use those over the top of your ormconfig.ts for whatever reason so if that is not the behaviour you want then you need to alter your .env.

If you are wondering what that database-index.ts thing we have going on is it is (simplified):

import * as Entities from './entity';
import * as Migrations from './migration';

export const entities = [
  Entities.User,
  Entities.Organisation,
  Entities.Role,
  Entities.Contract,
];

export const migrations = [
    Migrations.PaymentUpdates1583427782841,
    Migrations.PaymentType1583091842118,
    Migrations.AddPaymentType1583062412093,
    Migrations.CurrencyAndCountry1582976070556,
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeORM: "No migrations pending" when attempting to run ...
I have a new web app and I've written a migrator to create a user table. However, no matter what I try, typeorm...
Read more >
Migration troubleshooting in development - Prisma
This guide describes how to resolve issues with Prisma Migrate in a development environment, which often involves resetting your database.
Read more >
Troubleshoot the data migration service - Google Support
For details on using a search operator, go to Search operators you can use with Gmail. If the message can't be found in...
Read more >
Troubleshooting Migration Manager - Microsoft 365
Verify that the Windows account associated with the agent has read ... The CSV file used to do bulk migration cannot have duplicate...
Read more >
Use the Jira Cloud Migration Assistant to migrate
It won't delete anything from either your Server or Cloud sites. ... After you agree to app migration, you can still select Revoke...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found