'NestJS project starting when i running migration generate
When i running npm run typeorm migration:generate -- -n CreateUserTable
migration successfully generates, but at the same time my project is starting. When i running migration:create
all works fine and project doesn't starts.
I tried
- change
ts-node
tonode
. - run
npx typeorm
instead ofnpm run typeorm
- changing
dist
folder tosrc
- create
mig:gen
scripts
Here's error log
> ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli "migration:generate" "-n" "CreateUserTable"
[Nest] 6648 - 2022-01-27 19:23:24 LOG [NestFactory] Starting Nest application...
[Nest] 6648 - 2022-01-27 19:23:24 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
AlreadyHasActiveConnectionError: Cannot create a new connection named "default", because connection with such name already exist and it
now has an active connection session.
at AlreadyHasActiveConnectionError.TypeORMError [as constructor] (C:\Users\whitered932\Projects\wr-todo\src\error\TypeORMError.ts:7
:9)
at new AlreadyHasActiveConnectionError (C:\Users\whitered932\Projects\wr-todo\src\error\AlreadyHasActiveConnectionError.ts:8:9)
at ConnectionManager.create (C:\Users\whitered932\Projects\wr-todo\src\connection\ConnectionManager.ts:57:23)
at C:\Users\whitered932\Projects\wr-todo\src\globals.ts:77:35
at step (C:\Users\whitered932\Projects\wr-todo\node_modules\tslib\tslib.js:143:27)
at Object.next (C:\Users\whitered932\Projects\wr-todo\node_modules\tslib\tslib.js:124:57)
at fulfilled (C:\Users\whitered932\Projects\wr-todo\node_modules\tslib\tslib.js:114:62)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
[Nest] 6648 - 2022-01-27 19:23:24 LOG [InstanceLoader] AppModule dependencies initialized +7ms
[Nest] 6648 - 2022-01-27 19:23:24 LOG [InstanceLoader] TypeOrmModule dependencies initialized +2ms
Migration C:\Users\whitered932\Projects\wr-todo/src/migrations/1643293402567-CreateUserTable.ts has been generated successfully.
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +3152ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TypeOrmModule dependencies initialized +2ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] UserModule dependencies initialized +3ms
[Nest] 6648 - 2022-01-27 19:23:27 LOG [InstanceLoader] TaskModule dependencies initialized +1ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RoutesResolver] TaskController {/task}: +344ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task, GET} route +5ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task/:id, GET} route +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task, POST} route +2ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task/:id, PATCH} route +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RouterExplorer] Mapped {/task/:id, DELETE} route +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [RoutesResolver] UserController {/user}: +3ms
[Nest] 6648 - 2022-01-27 19:23:28 LOG [NestApplication] Nest application successfully started +7ms
Завершить выполнение пакетного файла [Y(да)/N(нет)]? Y
Here's my files package.json scripts
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
},
ormconfig.json
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "postgres",
"database": "postgres",
"entities": ["dist/**/*.js"],
"migrations": ["dist/migrations/*.js"],
"cli": {
"migrationsDir": "src/migrations"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|