gpt4 book ai didi

postgresql - TypeORM 迁移给出 Maximum call stack size exceeded error with Postgres

转载 作者:行者123 更新时间:2023-12-05 04:23:11 30 4
gpt4 key购买 nike

运行迁移时,出现以下错误。我最初在一个项目中有这个——现在我创建了一个新的空白项目,但仍然出现错误。这是 ormconfig.ts:


import { DataSource } from 'typeorm';

const env = {
"DB_HOST":"localhost",
"DB_PORT":5432,
"DB_USERNAME":"postgres",
"DB_PASSWORD":"postgres",
"DB_DATABASE":"task-management",
}

export const connectionSource = new DataSource({
migrationsTableName: 'migrations',
type: 'postgres',
host: env.DB_HOST,
port: env.DB_PORT,
username: env.DB_USERNAME,
password: env.DB_PASSWORD,
database: env.DB_DATABASE,
logging: false,
synchronize: false,
name: 'default',
migrations: ['migrations/**/*{.ts,.js}'],
});

我运行迁移:typeorm-ts-node-esm migration:run -d migrations/ormconfig.ts

出现以下错误:


Error during migration run:
RangeError: Maximum call stack size exceeded
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:43
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:35)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:27:42
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:27:22)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:30:17
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:35)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:30:17

我假设在 DirectoryExportedClassesLoader.ts 中存在一些循环依赖导致无限循环,所以我在 DirectoryExportedClassesLoader.ts 的第 26 行放置了一个 console.log(JSON.stringify(exported)),现在我得到:

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'DataSource'
| property 'driver' -> object with constructor 'PostgresDriver'
--- property 'connection' closes the circle
at JSON.stringify (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/typeormTest/src/util/DirectoryExportedClassesLoader.ts:29:25)

如果存在循环依赖,DirectoryExportedClassLoader.js 似乎保证会得到超出最大调用堆栈大小的错误,因为它在遇到对象属性时是自递归的。

请帮忙!

最佳答案

从 DataSource 配置对象更改此条目可解决问题。

migrations: []

这是经过大量反复试验才能解决的问题之一...

关于postgresql - TypeORM 迁移给出 Maximum call stack size exceeded error with Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73778521/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com