Nest: Cannot get typeorm and mysql working

Created on 1 Oct 2017  路  5Comments  路  Source: nestjs/nest

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 {createConnection} from 'typeorm';
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 theUserentity directly into theentities` 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.

type

Most helpful comment

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.

All 5 comments

@ShawnMercado your database.providers.ts should looks like this:

import { createConnection } from 'typeorm';

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

as from docs https://docs.nestjs.com/recipes/sql-typeorm

Hi @ShawnMercado,
Can you share the repo? I can't reproduce your issue.

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.

Hi @ShawnMercado,
Cool :slightly_smiling_face: Have a good day!

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.

Was this page helpful?
0 / 5 - 0 ratings