【发布时间】:2022-02-17 12:07:29
【问题描述】:
在我的 Nestjs TypeOrm 应用程序中,我想将我所有的数据库工件封装在一个名为 globe 的模式中。所以,我在ormconfig.ts中指明了架构
const DatabaseConfigForMigrations = {
name: 'countrydb',
type: 'postgres',
host: process.env.DB_HOST,
port: process.env.DB_PORT,
schema: 'globe',
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
synchronize: false,
logging: true,
entities: ['dist/src/**/*entity.js'],
migrations: ['dist/src/migrations/**/*.js'],
cli: {
migrationsDir: 'src/migrations',
},
options: { trustServerCertificate: true },
};
也在我的模型中。比如;
@Entity({ schema: 'globe' })
@ObjectType()
export class City {
@PrimaryGeneratedColumn()
@Field(() => Int)
id: number;
@Column()
@Field()
name: string;
@Column({ nullable: true })
@Field({ nullable: true })
touristic: boolean;
@Column({ nullable: true })
@Field(() => Int, { nullable: true })
population: number;
@ManyToOne(() => Country, (country) => country.cities)
@JoinColumn({ name: 'country_id' })
country: Country;
@Column({ type: 'int', name: 'country_id' })
countryId: number;
}
但是,不幸的是,当我运行yarn migration:run 时,error: error: schema "globe" does not exist 发生了。
如何让 TypeOrm 在我的 globe 架构中创建表?
【问题讨论】: