Reputation: 731
How can I set AUTO_INCREMENT
for @PrimaryColumn()
?
I know that @PrimaryGeneratedColumn()
does this but I want to have ID from the double
type.
Is it possible to have @PrimaryGeneratedColumn()
with double
type? if not have can I set AUTO_INCREMENT
for @PrimaryColumn()
?
Upvotes: 12
Views: 34402
Reputation: 4844
Please use this code.
import {Entity, PrimaryGeneratedColumn} from 'typeorm';
@Entity()
export class SomeWhat{
@PrimaryGeneratedColumn('increment')
public id: number;
....
For double
ID, we can't use AUTO_INCREMENT
. AUTO_INCREMENT
is just available for int
type.
@PrimaryGeneratedColumn
We can set AUTO_INCREMENT
at only @PrimaryGeneratedColumn
decorator.
The below code is the declaration of the @PrimaryGeneratedColumn
.
As you can see, we can use 2 types of strategy (increment, uuid).
(typeorm/decorator/columns/PrimaryGeneratedColumn.d.ts)
export declare function PrimaryGeneratedColumn(): Function;
export declare function PrimaryGeneratedColumn(options: PrimaryGeneratedColumnNumericOptions): Function;
export declare function PrimaryGeneratedColumn(strategy: "increment", options?: PrimaryGeneratedColumnNumericOptions): Function;
export declare function PrimaryGeneratedColumn(strategy: "uuid", options?: PrimaryGeneratedColumnUUIDOptions): Function;
@PrimaryColumn
But in this @PrimaryColumn
, there is no available strategy. This is just transforming the value to the primary key without generating.
(typeorm/decorator/columns/PrimaryColumn.d.ts)
export declare function PrimaryColumn(options?: ColumnOptions): Function;
export declare function PrimaryColumn(type?: ColumnType, options?: ColumnOptions): Function;
Upvotes: 17