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.

make primary column optional

See original GitHub issue

error message:

Use @PrimaryColumn decorator to add a primary column to your entity.
import { Column, Entity, Index } from "typeorm";

@Index("biARBL", ["co", "mth", "batchId", "batchSeq", "arLine"], {
  unique: true,
})
@Index(
  "biARBLApplied",
  ["co", "applyMth", "applyTrans", "applyLine", "mth", "batchId", "batchSeq"],
  {},
)
@Entity("bARBL", { schema: "dbo" })
export class BArbl {
  @Column("tinyint", { name: "Co" })
  co: number;

  @Column("smalldatetime", { name: "Mth" })
  mth: Date;

  @Column("int", { name: "BatchId" })
  batchId: number;

  @Column("int", { name: "BatchSeq" })
  batchSeq: number;

  @Column("smallint", { name: "ARLine", nullable: true })
  arLine: number | null;

  @Column("char", { name: "TransType", length: 1 })
  transType: string;
}

I can’t add @PimaryColumn on all fields of my index because one of them arLine is nullable.

_Originally posted by @saostad in https://github.com/typeorm/typeorm/issues/3704#issuecomment-573211839_

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Kononnablecommented, Mar 6, 2020

Typeorm requires entity to have primary key defined to work correctly and there are no plans to change that. If you don’t want to use primary key(or you’re forced not to use it) you can mark unique index as primary key and disable schema sync for such table. It would deceive ORM and you should be able to use such table.

2reactions
Maddimaxcommented, Sep 25, 2020

you can mark unique index as primary key

How can I mark a unique index as a primary key? I could not find anything in the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specifying optional properties for columns - IBM
You can specify optional properties for the columns that you define when creating a table. The optional column properties are described in the...
Read more >
Primary key with optional column - Oracle Communities
I have a compound primary key (Constraint) consisting of 2 columns. The 1st column is mandatory (can't be NULL) but the 2nd column...
Read more >
Primary Keys with Nullable Columns - MariaDB
7 introduced new behavior for dealing with primary keys over nullable columns. Take the following table structure: CREATE TABLE t1( c1 INT NOT...
Read more >
Solved: Automatically fill in primary column in dataverse
The way to do it to do what @Jcook described (Set the data type to automatic number), then, you also need to set...
Read more >
Why can I create a table with PRIMARY KEY on a nullable ...
The primary key constraint specifies that a column or columns of a table can contain only unique (non-duplicate), nonnull values. Technically, ...
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