我在MySQL 8.0.15中有一个数据库,并且数据库中有一个表,其中包含一个可空的DATE列,如下所示;
CREATE TABLE `sayaclar` (
`sayac_id` int(11) NOT NULL AUTO_INCREMENT,
`daire_id` int(11) DEFAULT NULL,
`sayac_no` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`urun_id` int(11) NOT NULL,
`marka_id` int(11) NOT NULL,
`model_id` int(11) NOT NULL,
`montaj_endeks` decimal(18,6) DEFAULT '0.000000',
`kc` decimal(3,2) DEFAULT NULL,
`rad_gucu` int(11) DEFAULT NULL,
`rad_uz` decimal(4,2) DEFAULT NULL,
`mahal` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`aktif` bit(1) NOT NULL DEFAULT b'1',
`aktif_tarihi` date NOT NULL,
`pasif_tarihi` date DEFAULT NULL,
PRIMARY KEY (`sayac_id`),
KEY `fk_sayaclar_daire_id` (`daire_id`),
CONSTRAINT `fk_sayaclar_daire_id` FOREIGN KEY (`daire_id`) REFERENCES `daireler` (`daire_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
这是我的插入函数;
sayaclar meter = new sayaclar
{
aktif = true,
aktif_tarihi = DateTime.Now,
pasif_tarihi = null,
urun_id = model.urun_id,
marka_id = model.marka_id,
model_id = modelId,
montaj_endeks = mountedIndex,
sayac_no = meterNumber,
daire_id = flatId
};
meter = ctx.sayaclar.Add(meter);
ctx.SaveChanges();
return meter.sayac_id;
当我尝试向该表中插入一条记录时,该函数会抛出EntityValidationError
并显示pasif_tarihi is required