question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

0.3.0: Connection "default" was not found for creating entities with dataSource

See original GitHub issue

Issue Description

The datasource I’m using:

export const dataSource = new DataSource({
  type: "postgres",
  url: process.env.DATABASE_URL,
  migrations: [path.join(__dirname, "./migrations/*")],
  entities: [path.join(__dirname, "./entities/*")],
  subscribers: [path.join(__dirname, "./subscribers/*")],
  logging: !__prod__,
  migrationsRun: true,
  synchronize: true,
});

and for a Post entity if I do

dataSource.getRepository(Post).create({...someEntity}).save() (or getTreeRepository)

This will complain that there is no default connection, it does not happen for the other basic methods insert, update, delete etc, I think it will have this problem for other methods like remove though, which aren’t sql methods

Expected Behavior

The post should be created and saved properly along with its tree parent/children if it exists, like in 0.2.x versions

Actual Behavior

Connection "default" was not found

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✅ No, I don’t have the time, but I can support (using donations) development. 5$
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
tirathsharma098commented, Nov 22, 2022

Screenshot from 2022-11-22 20-41-51

okay I think I know what is the problem. For now you need to set YourEntity.useConnection(dataSource) for each entity you have as a hotfix. I’ll push a PR for this issue.

I am using 0.3.10 still facing same issue.

1reaction
pleerockcommented, Mar 18, 2022

okay I think I know what is the problem. For now you need to set YourEntity.useConnection(dataSource) for each entity you have as a hotfix. I’ll push a PR for this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection "default" was not found with TypeORM
You are trying to create a repository or manager without the connection being established. Try doing this const shopkeeperRepository ...
Read more >
typeorm metadata not found | The AI Search Engine You Control
My project has 2 seperate connection datasources. One is to a readonly mysql database, the other is a postgres database. Everything on the...
Read more >
typeorm/typeorm - Gitter
Does anyone have some insight into how to use @TransactionManager() and @TransactionRepository() without creating typing errors?
Read more >
TypeORM - Amazing ORM for TypeScript and JavaScript (ES7 ...
More information on supported column types can be found here. # Creating a new DataSource. Now, when our entity is created, let's create...
Read more >
typeorm: CHANGELOG
// load entities, establish db connection, sync schema, etc. await dataSource.connect().
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found