我使用TypeORM连接到nodeJS中的postgresql数据库。我在以下地方遇到了这个奇怪的问题:
public static async organizationRelations(name){
let connection = getConnection();
const org = await connection.getRepository(Organization).find({
where:[{name: name}]
});
return org;
}
可以,但是:
public static async importOrganizations(body){
let connection = getConnection();
let objs = {};
let o = await connection.getRepository(Organization).save(this.createObjects(body, objs));
}
没有。
对于保存方法,我不断收到错误RepositoryNotFoundError: No repository for "Organization" was found. Looks like this entity is not registered in current "default" connection?
为什么它只能在一个功能中起作用,而不能在另一个功能中起作用?
答案 0 :(得分:0)
您是否尝试删除此行?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>SpringInAction</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringInAction</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案 1 :(得分:0)
我在mu App.ts中做到了这一点
private async databaseConnection(){
await createConnection(options).then(connection =>{
this.express.emit("app_started");
});
}
问题是我正在使用chai测试,并且在应用完全初始化之前就开始了测试。