Skip to main content
added 520 characters in body
Source Link

You have spaces in the column name. i.e. 'First Name' instead of 'FirstName', removing the spaces will solve your problem. If you want to preserve the spaces, use backticks '`' to wrap the string

Sample code:

columns = [ ('Last Name', 'First Name', 'Job', 'Country') ] #list of tuples

for p in columns:
    q = """ CREATE TABLE IF NOT EXISTS stud_data (`{col1}` VARCHAR(250),`{col2}` VARCHAR(250),`{col3}` VARCHAR(250),`{col4}` VARCHAR(250)); """
    sql_command = q.format(col1=p[0], col2=p[1], col3=p[2], col4 = p[3])


>>> sql_command
' CREATE TABLE IF NOT EXISTS stud_data (`Last Name` VARCHAR(250),`First Name` VARCHAR(250),`Job` VARCHAR(250),`Country` VARCHAR(250)); '

You have spaces in the column name. i.e. 'First Name' instead of 'FirstName', removing the spaces will solve your problem. If you want to preserve the spaces, use backticks '`' to wrap the string

You have spaces in the column name. i.e. 'First Name' instead of 'FirstName', removing the spaces will solve your problem. If you want to preserve the spaces, use backticks '`' to wrap the string

Sample code:

columns = [ ('Last Name', 'First Name', 'Job', 'Country') ] #list of tuples

for p in columns:
    q = """ CREATE TABLE IF NOT EXISTS stud_data (`{col1}` VARCHAR(250),`{col2}` VARCHAR(250),`{col3}` VARCHAR(250),`{col4}` VARCHAR(250)); """
    sql_command = q.format(col1=p[0], col2=p[1], col3=p[2], col4 = p[3])


>>> sql_command
' CREATE TABLE IF NOT EXISTS stud_data (`Last Name` VARCHAR(250),`First Name` VARCHAR(250),`Job` VARCHAR(250),`Country` VARCHAR(250)); '
Source Link

You have spaces in the column name. i.e. 'First Name' instead of 'FirstName', removing the spaces will solve your problem. If you want to preserve the spaces, use backticks '`' to wrap the string