大家晚上好,
抱歉,我是SQL新手。我的数据库中有两个表。第一个没关系,没问题,但是当我在第二个表中插入一个记录,这是第一个的JOIN时,我收到以下错误:
SQL query: Edit Edit
INSERT INTO `clihelp`.`commandExample` (
`commandExampleId` ,
`_code` ,
`_cliCommandId` ,
`example` ,
`created` ,
`updated`
)
VALUES (
'', 'WI', '00010', 'The following command is the same command as the Get-Service -Name Schedule
gsv -n Schedule',
CURRENT_TIMESTAMP ,
CURRENT_TIMESTAMP
)
MySQL said: Documentation
#1366 - Incorrect integer value: '' for column 'commandExampleId' at row 1
这是我的第一张表:
CREATE TABLE `cliCommand` (
`cliCommandId` mediumint(5) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT 'Autoincrement for each code group',
`code` varchar(255) NOT NULL COMMENT 'Command unique code shared with users to enable search using this code.',
`os` varchar(255) DEFAULT NULL COMMENT 'Operating Systems this command works with',
`tags` text COMMENT 'tags for the command',
`title` text NOT NULL COMMENT 'command short description/title to be displayed in search result listing along with command code and os',
`script` text COMMENT 'Help/Manual for the command or complete script',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`code`,`cliCommandId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Keeps all cli commands with meta data & description'
这是我的第二张桌子,一旦我遇到问题:
CREATE TABLE `commandExample` (
`commandExampleId` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Autoincrement key for internal purposes',
`_code` varchar(255) NOT NULL,
`_cliCommandId` int(11) DEFAULT NULL,
`example` text COMMENT 'an example associated with this command, there could be multiple examples associated with a command, each as a new record in this table',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`commandExampleId`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COMMENT='Keeps examples, if any, for a command to be displayed'
你知道如何解决它吗?
非常感谢您的帮助。
答案 0 :(得分:1)
cliCommandId
被定义为整数列,但您尝试插入空字符串。这是错误的来源。由于它是一个自动增量列,您可能希望MySQL处理赋值。在这种情况下,只需在cliCommandId
语句中完全省略INSERT
。然后MySQL应该自动为你分配一个值。
INSERT INTO clihelp.commandExample (
`_code`,
`_cliCommandId`,
`example`,
`created`,
`updated`
)
VALUES (
'WI',
'00010',
'The following command is the same command as the Get-Service -Name Schedule gsv -n Schedule',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
)
答案 1 :(得分:1)
commandExampleId
列的值不应为空字符串。它应该是NULL
:
INSERT INTO `clihelp`.`commandExample` (
`commandExampleId` ,
`_code` ,
`_cliCommandId` ,
`example` ,
`created` ,
`updated`
)
VALUES (
NULL,
'WI',
'00010',
'The following command is the same command as the Get-Service -Name Schedule gsv -n Schedule',
CURRENT_TIMESTAMP ,
CURRENT_TIMESTAMP
)