我有一个像这样创建的表:
CREATE TABLE `PersonalInformation` (
`user_id` int(10) unsigned NOT NULL,
`language_code` char(2) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`first_name` varchar(64) NOT NULL,
`last_name` varchar(64) NOT NULL,
`photo` char(64) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`user_id`),
KEY `language_code` (`language_code`),
CONSTRAINT `personalinformation_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `Users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `personalinformation_ibfk_2` FOREIGN KEY (`language_code`) REFERENCES `Languages` (`code-639-1`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我不想在不填写所有NOT NULL
文件的情况下插入。然而我仍然可以执行这样的插入:
INSERT INTO `PersonalInformation` (`user_id`, `photo`) VALUES (13, 'aaa')
而不是错误我在first_name
和last_name
中获得了一个包含空字符串的新条目。我启用了严格模式,但这仍然是这样的。这可以预防吗?