上传数据库时出错 table - Python mysql

Error while uploading a database table - Python mysql

我几乎是 MySQL 数据库的新手。
我正在尝试输入,但在控制台中发现此错误:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'total issues (Timestamp, Count issues, Project) VALUES ('2020-04-17', '908', ''G' at line 1

这是我正在尝试的代码 运行:

uploadMap = {
    'current total issues': 'apiUrl0...',
    'current total unresolved issues': 'apiUrl1...',
    'total created in the week': 'apiUrl2...',
    'total blocker created in week': 'apiUrl3...'
}

for project in ('Graphic', 'Develop'):
    for tableName, url in uploadMap.items():

        sql = f"INSERT INTO {tableName} (Timestamp, Count issues, Project) VALUES (%s, %s, %s)"

        val = (todaySql, getTotal(url + project), project)

        cursor.execute(sql, val)

一些说明:

class jiraDates:
    def __init__(self):
        self.format = ('%Y', '%m', '%d')

    def getJiraDate(self, daysBack):
        dateBack = datetime.today() - timedelta(days=daysBack)
        return '-'.join([dateBack.strftime(ref) for ref in self.format])

    def getSqlDate(self, daysBack):
        return datetime.strptime(self.getJiraDate(daysBack), '-'.join(self.format))

todaySql = jiraDates().getSqlDate(0)



希望没什么大不了的...!

jordanm说的没有错。如果名称大于字母组合,则需要使用反引号(尽管我强烈建议使用蛇形大小写,例如 name_of_the_table)。
您需要确保的另一件事是日期必须采用以下日期格式:datetime.date(int(year), int(months), int(date))

所以你必须改变这两行:

def getSqlDate(self, daysBack):
    jiraDate = self.getJiraDate(daysBack).split('-')
    return datetime.date(int(jiraDate[0]), int(jiraDate[1]), int(jiraDate[2]))

sql = f"INSERT INTO `{tableName}` (Timestamp, `Count issues`, Project) VALUES (%s, %s, %s)"