其实类似的问题还有很多,我也解决不了这个问题。我正在使用 codeigniter 框架。当我insert通过传递 php 对象来调用 ActiveRecord 的方法时,它会按其值或 null 发送所有属性。它会导致cannot be null.错误。
表结构:
CREATE TABLE `scheduledTasks` (
`id` int(11) NOT NULL,
`type` varchar(255) COLLATE utf8_bin NOT NULL,
`createTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`executionTime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ownerUserId` int(11) DEFAULT NULL,
`subjectUserId` text COLLATE utf8_bin,
`detail` text COLLATE utf8_bin,
`isExecuted` int(1) DEFAULT '0'
);
ALTER TABLE `scheduledTasks`
ADD PRIMARY KEY (`id`);
ALTER TABLE `scheduledTasks`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
Run Code Online (Sandbox Code Playgroud)
我尝试过的查询:
INSERT INTO `scheduledTasks` (`id`, …Run Code Online (Sandbox Code Playgroud)