MySQL创建表格错误:数据类型不匹配的解决方案
{"title":"def execl(): # 创建SQL表格\nsql = """CREATE TABLE IF NOT EXISTS test3 (\n 序号 INTEGER PRIMARY KEY,\n 链接 VARCHAR(255),\n 标题 VARCHAR(255),\n 时间 DATE\n )engine = innodb default charset=utf8;\n """\n cur.execute(sql)\n为什么上述代码显示(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '序号 INT(11),\n 链接 VARCHAR(255),\n ' at line 2")内容:该错误是由于SQL语句中的数据类型不正确导致的。在创建表时,数据类型应该是INT而不是INTEGER。正确的SQL语句应该是:\n\npython\ndef execl(): # 创建SQL表格\n sql = \"\"\"CREATE TABLE IF NOT EXISTS test3 (\n `序号` INT(11) PRIMARY KEY,\n `链接` VARCHAR(255),\n `标题` VARCHAR(255),\n `时间` DATE\n )engine = innodb default charset=utf8;\n \"\"\"\n cur.execute(sql)\n\n\n改正后的代码中,将INTEGER改为INT(11),以便指定整数的长度。"}
原文地址: https://www.cveoy.top/t/topic/pBjx 著作权归作者所有。请勿转载和采集!