The @AutoIncrement decorator is used to make an attribute auto-increment, it is a shortcut for setting the autoIncrement option of the Attribute decorator to true.
@AutoIncrement
autoIncrement
Some dialects require the field to be a primary key.
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> { @Attribute(DataTypes.INTEGER) @PrimaryKey @AutoIncrement declare id: number;} Copy
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> { @Attribute(DataTypes.INTEGER) @PrimaryKey @AutoIncrement declare id: number;}
Optional
The
@AutoIncrement
decorator is used to make an attribute auto-increment, it is a shortcut for setting theautoIncrement
option of the Attribute decorator to true.Some dialects require the field to be a primary key.
Example