NOT NULL not working
loic-roux-404 opened this issue · comments
Hi
First, thanks for you work it's a very useful and well builded tool.
When i use a model with for example
@Model("user")
class UserModel extends BaseModel {
@Field({
type: FieldType.INT,
primary: true,
length: 11,
autoIncrement: true,
})
id!: number;
@Field({ type: FieldType.STRING, length: 30 })
name!: string;
@Field({ type: FieldType.STRING, length: 30 })
familyName!: string;
@Field({ type: FieldType.STRING, length: 30 })
email!: string;
@Field({ type: FieldType.STRING, length: 30 })
token?: string;
@Field({ type: FieldType.STRING, length: 30 })
secret!: string;
@Field({ type: FieldType.BOOLEAN })
isValid!: boolean;
}
And i insert the object
payload = {
name: 'toto'
}
connectDb();
const id = await model.insert(payload);
Error isn't throwed instead fields like secret
, token
are required with the !
Because you use "!" to declare that the field is not nullable, so you should also ensure that the field value is passed when inserting. If you want to declare an empty field, you should use "?" instead of "!"
Thanks, it's not the behaviour i used to...