make primary column optional
See original GitHub issueerror 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:
- Created 4 years ago
- Reactions:6
- Comments:10 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
How can I mark a unique index as a primary key? I could not find anything in the documentation.