Connection \"default\" was not found.
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.22
Steps to reproduce or a small repository showing the problem:
I have my createConnection file as follows.
import { getConnectionOptions, createConnection, Connection } from "typeorm";
export let connection: Connection | undefined = undefined;
export const createTypeORMConnection = async () => {
console.log(process.env.NODE_ENV!);
const connectionOptions = await getConnectionOptions(process.env.NODE_ENV!);
console.log(connectionOptions);
connection = await createConnection(connectionOptions);
return connection;
};
The console logs are printing fine.
And my Resolver I am using the connection object exported here and using the save method.
console.log("env", process.env.NODE_ENV, connection!.name);
const user = await connection!
.getRepository<User>(User)
.create({
firstName,
lastName,
email,
password: hashedPassword
})
.save();
console.log(`register - Create User: ${user} -> Done`);
but before hitting the register - create user console log in the save method itself I am getting Connection default was not found.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12
Top Results From Across the Web
Connection "default" was not found with TypeORM
Solution is to make sure that you have exactly the same version installed in each package. To be on the safe side, delete...
Read more >0.3.0: Connection "default" was not found for creating entities ...
Issue Description The datasource I'm using: export const dataSource = new DataSource({ type: "postgres", url: process.env.
Read more >Connection "default" was not found with TypeORM-postgresql
I use TypeORM with NestJS and I am not able to save properly an entity. The connection creation works, postgres is running on...
Read more >connectionnotfounderror: connection default'' was not found
ConnectionNotFoundError: Connection "default" was not found. due to the fact that my typeORM entity did have an @Entity() decorator as well as that...
Read more >Does anyone know any real world projects that use typeorm ...
"RepositoryNotFoundError: No repository for "MyModelName" was found. Looks like this entity is not registered in current "default" connection?".
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Guys, I was facing the same problem. Took me a while to realize that I was calling a repository outside the method:
This method was called inside the routes of express and tries to connect to the repository before the connection even exists.
Had this same issue. I fixed it by spreading in the connection option to createConnection and changing the name to default
const connectionOptions = await getConnectionOptions(NODE_ENV)createConnection({ ...connectionOptions, name: "default" } as any)Ts lint did not like the override but the code works.