大家晚上好,
抱歉,我是 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'
这是我的第二张 table ,有一次我遇到了问题:
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'
你知道如何解决这个问题吗?
提前非常感谢您的帮助。
最佳答案
cliCommandId
已定义为整数列,但您正尝试插入空字符串。这就是错误的根源。由于它是一个自动增量列,您可能希望 MySQL 来处理分配该值。在这种情况下,只需在 INSERT
语句中完全省略 cliCommandId
即可。然后 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
)
关于mysql - 我的 JOIN 表的错误消息。错误 1366,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40856567/