New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.3.0: Connection "default" was not found for creating entities with dataSource #8758
Comments
Did you call |
Yep, I've checked that things work with insert, update and delete methods already, so that should also be the case that I need to initialize before those methods work |
I've had quick look at the code, and the insert method for example uses this.createQueryBuilder, whereas the create method uses this.connection etc, which might be the problem it tries to find a default connection. With the old connection API, it sets the default connection to be the first datasource we use I believe, do we have a similar option here for new DataSource(..)? |
can you provide the whole stack trace in order to understand where exactly this error comes from |
do you have entities extending |
Yep import { Updoot } from "@entities/Updoot";
import { User } from "@entities/User";
import { Field, Int, ObjectType } from "type-graphql";
import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
Tree,
TreeChildren,
TreeParent,
UpdateDateColumn,
} from "typeorm";
@ObjectType()
@Entity()
@Tree("closure-table")
export class Post extends BaseEntity {
@Field()
@PrimaryGeneratedColumn("uuid")
id: string;
@Field({ nullable: true })
@Column({ nullable: true })
parentId?: string;
@TreeParent()
parent: Post;
@Field(() => Int)
@Column({ default: 1 })
level: number;
@Field(() => [Post], { nullable: true })
@TreeChildren()
children: Post[] | null;
@Field()
@Column({ default: "" })
title: string;
@Field()
@Column({ default: "" })
text: string;
@Field({ nullable: true })
@Column({ nullable: true })
gifId?: string;
@Field(() => Int)
@Column({ default: 0 })
points: number;
@Field(() => Int)
@Column({ default: 0 })
commentsCount: number;
@Field()
@Column({ type: "double precision" })
ranking: number;
@Field()
@Column({ default: false })
edited: boolean;
@Field(() => Int, { nullable: true })
voteStatus: number | null; // 1 or -1 or null
@Field()
@Column()
creatorId: string;
/* Post structure is more complicated so we cannot just set onDelete: "CASCADE"
when deleting the user and will have to manually delete ourselves :C */
@Field(() => User)
@ManyToOne(() => User, (user) => user.posts)
creator: User;
@OneToMany(() => Updoot, (updoot) => updoot.post)
updoots: Updoot[];
@Field()
@CreateDateColumn()
createdAt: Date;
@Field()
@UpdateDateColumn()
updatedAt: Date;
} |
okay I think I know what is the problem. For now you need to set |
fixed by #8764 |
Problem still exists in v0.3.10. I init my project by typeorm, did't change any code except db user/password import { getRepository } from "typeorm"
import { NextFunction, Request, Response } from "express"
import { User } from "../entity/User"
export class UserController {
private userRepository = getRepository(User)
async all(request: Request, response: Response, next: NextFunction) {
return this.userRepository.find()
}
...... ConnectionNotFoundError: Connection "default" was not found. |
This is still a problem in 0.3.11. @pleerock Can you advise? When using some methods everything is fine. When using the deprecated
It may be only when using queryBuilder. I'm still trying to narrow it down. |
I updated my comment above to strike out what eventually worked. To recap...
This is a bug. The method is deprecated but should still work. All other approaches to access data work fine before and after this call. The datasource is confirmed to be However, if I access a repository in the new, prescribed method through
|
I can confirm this issue still exists in 0.3.17 What is the accepted way of declaring a DataSource and also using BaseEntity (ActiveRecord pattern)? I always get Trying to migrate from typeorm 0.2.20 to 0.3.17 and can not figure out how to migrate the code base from ConnectionOptions to DataSource. Anybody already been through the process? |
I have tried to set ".useDataSource(...)" on each of my Entities, but I'm still getting the same error. |
I was having this problem when using
So I switched to
And I created a module called DatabaseModule
my app.module
This worked perfectly for me replacing the deprecated getRepository(), and apparently it works well inside entities too, this has been my solution so far |
Issue Description
The datasource I'm using:
and for a Post entity if I do
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
Relevant Database Driver(s)
aurora-mysql
aurora-postgres
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: