Error: Entity metadata was not found

See original GitHub issue
// conversation_pairs.ts

@Entity()
export class ConversationPairs {

  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(type => Users, user_id => user_id.conversation_pairs, {
    cascadeRemove: true,
    nullable: false
  })
  user_id: Users;

  @ManyToOne(type => Agents, agent_id => agent_id.conversation_pairs, {
    cascadeRemove: true,
    nullable: false
  })
  agent_id: Agents;
}

// user.ts

@Entity()
export class Users {
  @PrimaryGeneratedColumn()
  id: number;

  @OneToMany(type => ConversationPairs, conversation_pairs => conversation_pairs.user_id)
  conversation_pairs: ConversationPairs[];
}

// agent.ts

@Entity()
export class Agents {

  @PrimaryGeneratedColumn()
  id: number;

  @OneToMany(type => ConversationPairs, conversation_pairs => conversation_pairs.agent_id)
  conversation_pairs: ConversationPairs[];
}

I have these 3 files and getting this error when I start my app.

Error: Entity metadata for ConversationPairs#user_id was not found.
    at /Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:272:27
    at Array.forEach (native)
    at /Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:269:38
    at Array.forEach (native)
    at EntityMetadataBuilder.build (/Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:268:25)
    at EntityMetadataBuilder.buildFromMetadataArgsStorage (/Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:152:21)
    at Connection.buildMetadatas (/Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/connection/Connection.js:552:18)
    at Connection.<anonymous> (/Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/connection/Connection.js:174:30)
    at step (/Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/connection/Connection.js:32:23)
    at Object.next (/Users/xuanrong/Sites/calllevels/dbs-chat/node_modules/typeorm/connection/Connection.js:13:53)

Not sure what to do, need some help on this.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:28
  • Comments:66 (10 by maintainers)

github_iconTop GitHub Comments

222reactions
tomkroeningcommented, Apr 29, 2017

I ran into the same issue.

TypeORM is very difficult to debug with args and meta data classes/collections all over the place. After many hours I was able to figure it out.

So this relationship is failing because EntityMetadataBuilder.ts is trying to tie the type of the ManyToOne column with a known entity type using “===”.

var inverseEntityMetadata = entityMetadatas.find(function (m) { return m.target === relation.type || (typeof relation.type === "string" && m.targetName === relation.type); });

Looking at relation.type I could see that it is the same “type” as m.target however they were not pointing to the same reference of the defined type. It seemed to me as if my related class was being loaded by node more than once. After reading about how node caches modules I was able to fix my problem by making sure all of my import statements were referencing the same file including uppercase/lowercase letters in the string.

In one file I had

import { Category } from "./models/category";

and the other I had

import { Category } from "./Category";

Notice the uppercase “C”. After replacing with a lowercase “c” everything worked as expected.

106reactions
pleerockcommented, Jun 17, 2017

Conclusion: this error happening when you have misspelled your entity name, misspelled import paths or did not include your entity in connection configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity metadata for Role#users was not found - Stack Overflow
I am using NestJS with PostgreSQL and I had the same issue. The problem was by me is that I forgot to import...
Read more >
typeormerror: entity metadata for was not found. - You.com
I am using NestJS with PostgreSQL and I had the same issue. The problem was by me is that I forgot to import...
Read more >
Fix for EntityMetadataNotFound: No metadata was found in ...
The entity is a Typescript class that maps to a table in the database. If you defined the entities with typeorm decorator for...
Read more >
typeorm/typeorm - Gitter
I feel like I'm close but I get the error: TypeORM connection error: Error: Entity metadata for Toy#creator was not found. Check if...
Read more >
TypeORM - No metadata for "User" was found. - Reddit
EntityMetadataNotFound : No metadata for "User" was found. at new EntityMetadataNotFoundError (src/error/EntityMetadataNotFoundError.ts:9:9) ...
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