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.

MissingPrimaryColumnError when primary defined in relation

See original GitHub issue

I have an entity described that:

import { Test } from "./test";
import { Product } from "./product";

import { Table, Column, ManyToOne } from "typeorm";

@Table()
export class Result {
    @ManyToOne(type => Test, { primary: true, nullable: false })
    public test: Test;

    @ManyToOne(type => Product, { primary: true, nullable: false })
    public product: Product;

    @Column()
    public primaryValue: number;

    @Column()
    public secondaryValue: number;
}

And I have an error on launch: Error! { MissingPrimaryColumnError: Entity "Result" does not have a primary column. Primary column is required to have in all your entities. Use @PrimaryColumn decorator to add a primary column to your entity.

Does the primary in relations option doesn’t work yet or it’s just a bug in checking if primary is defined?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rostamianicommented, Mar 17, 2021

maybe using indices can help?

Excuse me, How indices can help with this error? I added @Index() to both keys and nothing solved

(Your link is no longer valid)

1reaction
MichalLytekcommented, Sep 26, 2016

Yes, thanks! It works great now 😄 Sorry for asking this kind of question but the docs is empty and website documentation was updated today and I haven’t checked it yet 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

It's possible, create a table without primary key in TypeOrm?
Ciao, no you can't because its required for entities to have a primary column in terms of ORM because most of ORM operations...
Read more >
TypeORM - Entity - Tutorialspoint
PrimaryGeneratedColumn() decorator class is used to represent that the id column is the primary key column of the Student entity.
Read more >
MissingPrimaryColumnError - typeorm
Inherited from Error.message. Defined in /Users/lesha/trunk/sandbox/typeorm/node_modules/typedoc/node_modules/typescript/lib/lib.es5.d.ts:886 ...
Read more >
Entities - typeorm - GitBook
Basic entities consist of columns and relations. Each entity MUST have a primary column (or ObjectId column if are using MongoDB).
Read more >
0.3.7 (2022-06-29) | TypeORM Docs
Define relation columns, and order by them instead. ... If related entity has multiple primary keys, and you want to point to multiple...
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 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