我有一个nestjs
应用程序,我使用typeorm
,PostgreSQL
。这个应用程序在linux/mac操作系统上运行良好。但在windows 11中,迁移表上没有找到数据,这就是为什么PostgreSQL数据库上没有创建表。当我运行npm run start:dev
时,它在终端上显示以下消息:
$ npm run start:dev
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> service@1.0.0 start:dev
> nest start --watch --preserveWatchOutput
[2:00:24 PM] Starting compilation in watch mode...
[2:01:01 PM] Found 0 errors. Watching for file changes.
.......................................................................................
.......................................................................................
{"level":30,"ctx":"InstanceLoader","msg":"AppModule dependencies initialized"}
{"level":30,"ctx":"DBLogger","query":"SELECT * FROM current_schema()"}
{"level":30,"ctx":"DBLogger","msg":"No classes were found using the provided glob pattern: \"dist/src/server/migration/*{.ts,.js}\""}
{"level":30,"ctx":"DBLogger","query":"CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\""}
{"level":30,"ctx":"DBLogger","query":"SELECT version();"}
{"level":30,"ctx":"DBLogger","query":"SELECT * FROM \"information_schema\".\"tables\" WHERE \"table_schema\" = 'public' AND \"table_name\" = 'migrations'"}
{"level":30,"ctx":"DBLogger","query":"SELECT * FROM \"migrations\" \"migrations\" ORDER BY \"id\" DESC","parameters":[]}
{"level":30,"ctx":"DBLogger","msg":"No migrations are pending"}
{"level":30,"ctx":"InstanceLoader","msg":"TypeOrmCoreModule dependencies initialized"}
.......................................................................................
.......................................................................................
{"level":30,"ctx":"NestApplication","msg":"Nest application successfully started"}
我已经通过运行npm run build
进行了构建。然后运行npm run typeorm -- migration:run
npm run typeorm -- migration:run
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> service@1.0.0 typeorm
> typeorm-ts-node-esm -d ./ormconfig.ts "migration:run"
query: SELECT * FROM current_schema()
query: SELECT version();
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = 'public' AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
No migrations are pending
标准配置.ts代码:
import * as dotenv from 'dotenv';
import { DataSource } from 'typeorm';
dotenv.config();
const connection = new DataSource({
type: 'postgres' as const,
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'mango',
database: 'loyalty',
entities: ['src/server/entity/*.{ts,js}'],
migrations: ['src/server/migration/*.{ts,js}'],
extra: {
ssl: false,
},
});
export default connection;
应用程序模块.ts
@Module({
imports: [
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => {
return {
type: 'postgres',
entities: [],
synchronize: false,
migrations: ['dist/src/server/migration/*{.ts,.js}'],
migrationsTableName: 'migrations',
migrationsRun: true,
};
},
}),
],
controllers: [],
providers: [],
})
export class AppModule {
constructor(private connection: Connection) {}
}
文件结构:
project
|--------> dist
|--------> src
|--------> server
|---------> migration
|--------> src
|--------> server
|---------> migration
任何建议都将不胜感激。先谢了。
**更新:**我也在Docker容器中运行这个项目,仍然是同样的问题。
1条答案
按热度按时间u0sqgete1#
我认为你在问这个问题之前应该先研究一下
尝试this answer