如果项目以开发模式启动,NestJS 会自动创建表而不应用迁移
NestJS Creating tables automatically without applying migrations if project is started in dev mode
所以我有一个使用 NestJS + TypeORM 的项目。
当我在 运行 进行任何迁移之前使用 yarn start:dev
在开发模式下启动项目时(此时创建了数据库,但没有任何 tables) , 除了 migrations table.
之外,它会自动在数据库中创建所有 table
在那之后,如果我们尝试 运行 迁移,它会抛出一个错误,指出 table 已经存在,这似乎是真实的。
那么,为什么 NestJS 会在 yarn start:dev
上自动创建 table?
不确定如何使用 yarn start:dev
自动创建 table。
Synchronize 和 migrationsRun 均为 false。
AutoLoadentites 设置为 true
嘿,尝试将 synchronize
设置为 false
。
.env
默认情况下被解析为字符串。即使使用 this.configService.get<boolean>
。
例如
createTypeOrmOptions(): TypeOrmModuleOptions {
return {
...
synchronize: this.configService.get<string>('TYPEORM_SYNCHRONIZE') === 'true' ? true : false,
...
};
}
所以我有一个使用 NestJS + TypeORM 的项目。
当我在 运行 进行任何迁移之前使用 yarn start:dev
在开发模式下启动项目时(此时创建了数据库,但没有任何 tables) , 除了 migrations table.
在那之后,如果我们尝试 运行 迁移,它会抛出一个错误,指出 table 已经存在,这似乎是真实的。
那么,为什么 NestJS 会在 yarn start:dev
上自动创建 table?
不确定如何使用 yarn start:dev
自动创建 table。
Synchronize 和 migrationsRun 均为 false。 AutoLoadentites 设置为 true
嘿,尝试将 synchronize
设置为 false
。
.env
默认情况下被解析为字符串。即使使用 this.configService.get<boolean>
。
例如
createTypeOrmOptions(): TypeOrmModuleOptions {
return {
...
synchronize: this.configService.get<string>('TYPEORM_SYNCHRONIZE') === 'true' ? true : false,
...
};
}