如何解决找不到连接“默认”
错误
ConnectionNotFoundError: Connection "default" was not found.
我开始使用依赖倒置原则时收到此错误。
ormconfig.json
{
"name": "default","type": "postgres","host": "localhost","port": 5432,"username": "postgres","password": "docker","database": "customer","entities": [
"./src/modules/**/infra/typeorm/entities/*.ts"
],"migrations": [
"./src/shared/infra/typeorm/migrations/*.ts"
],"seeds": [
"./src/shared/infra/typeorm/seeds/*.ts"
],"cli": {
"migrationsDir": "./src/shared/infra/typeorm/migrations"
}
}
立即列出
Column type for Admin#email is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
解决方法
您必须使用
createConnection
与数据库建立连接 功能。
const connection = await createConnection();
createConnection
函数返回一个connection
。使用此connection
进行所有数据库操作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。