'How to fix: No changes in database schema were found - cannot generate a migration?
I searched a lot and there are several questions like this however most of them do not have any answer or are not relevant to me.
I'm using TypeORM(v0.2.45) with Postgres driver and my entities/schemas are working fine with synchronize
mode enabled.
My goal is to reverse generate migrations from the existing entities however it fails somehow.
This is what I get when trying to generate migrations
❯ npm run migration:generate Coffee
> [email protected] migration:generate
> npm run build && npm run typeorm migration:generate -- -n "Coffee"
> [email protected] prebuild
> rimraf dist
> [email protected] build
> cross-env NODE_ENV=production nest build
> [email protected] typeorm
> cross-env NODE_ENV=production ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config dist/src/common/setup/config/orm.config.js "migration:generate" "-n" "Coffee"
No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command
Here are my npm scripts for TypeORM
{
"typeorm": "cross-env NODE_ENV=production ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config dist/src/common/setup/config/orm.config.js",
"migration:generate": "npm run build && npm run typeorm migration:generate -- -n",
"migration:run": "npm run typeorm migration:run"
}
orm.config.ts
import { Env } from '../../env';
import { join } from 'path';
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';
export default {
database: Env.isTest ? ':memory:' : process.env.DB_DATABASE || 'dri',
type: Env.isTest ? 'sqlite' : 'postgres',
port: Number(process.env.DB_PORT || 5432),
username: process.env.DB_USERNAME || 'dri-user',
password: process.env.DB_PASSWORD || 'dri-secret',
host: process.env.DB_HOST || '127.0.0.1',
...(!Env.isProd && {
synchronize: true,
synchronizeOptions: {
force: true,
},
}),
autoLoadEntities: true,
entities: [Env.isTest ? 'src/**/*.entity{.ts,.js}' : join(__dirname, './**/*.entity{.ts,.js}')],
keepConnectionAlive: true,
namingStrategy: new SnakeNamingStrategy(),
logging: Env.isDev ? 'all' : 'error',
migrations: [join(__dirname, './**/*.entity{.ts,.js}')],
cli: {
migrationsDir: 'migrations',
},
};
When I try to create a migration - it works but I want to generate it from the existing schema which is failing at the moment. 🤕
p.s.
I tried it with all the tables removed and also having em all in place but the result is the same - did not generate anything.😔
Solution 1:[1]
try delete dist
folder,
re-run npm run migration:generate Coffee
, or you can split npm run build
and then generate migration later
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hai Alison |