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.

Cannot get typeorm and mysql working

See original GitHub issue

Hi, I followed the examples as best I could from the documentation, but no matter what I change I get this error:

No repository for "User" was found. Looks like this entity is not registered in current "default" connection?

My database.providers.ts file looks like this

import {userProviders} from "../UserModule/user.providers";
import {User} from "../UserModule/user.entity";

export const databaseProviders = [
    {
        provide: 'DbConnectionToken',
        useFactory: async () => await createConnection({
            type: 'mysql',
            host: 'localhost',
            port: 3306,
            username: 'root',
            password: 'root',
            database: 'mydb',
            entities: [
                __dirname + '/../**/*.entity{.ts,.js}',
            ],
            synchronize: true
        }),
    },
];

I tried putting the User entity directly into the entities option, but that had no effect. I’ve also fiddled with that glob string about every which way possible. I’m completely out of ideas as to what to try.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ShawnMercadocommented, Oct 1, 2017

Thanks for looking into it guys. I went through all the files again, and I finally found the discrepancy. I forgot to put the @Entity() annotation on the User object… my bad.

It does feel like this should throw a more specific error, but I imagine that has nothing to do with nestjs and only with the typeorm library.

0reactions
lock[bot]commented, Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot connect to a MySQL database using NestJS and ...
I am trying to create a new project using NestJS and I want to use a MySQL database with the help of TypeORM...
Read more >
Caching queries - typeorm - GitBook
This will execute a query to fetch all admin users and cache the results. Next time you execute the same code, it will...
Read more >
Connection Options | TypeORM Docs
get (name: string) . Connection names for different connections cannot be same - they all must be unique. If connection name is not...
Read more >
TypeORM and MySql Configuration for NestJS - Medium
Introduction. Today I will try to explain different approaches to take while configuring the MySQL database with NestJS using typeorm. To get a...
Read more >
SQL (TypeORM) | NestJS - A progressive Node.js framework
Since it's written in TypeScript, it works pretty well with the Nest framework. Getting started#. To start the adventure with this library we...
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