在我的数据库中,我使用raw_input
来允许用户向数据库中输入数据,问题是我给每个数据记录分配了一个ID,这是表的主键。在
username = raw_input("What would you like your username to be? ")
email = raw_input("What is your email address? ")
firstName = raw_input("What is your first name? ")
surname = raw_input("What is your surname? ")
age = raw_input("How old are you? ")
password = raw_input("What is your password?") #Encryption method will be added later
age = int(age) #Changing the age variable into an integer so it can be inputted into the database
#DB part
conn = db.connect('apollo.db') #Connecting to the database
cursor = conn.cursor()
cursor.execute("INSERT INTO users VALUES(?, ?, ?, ?, ?, ?)",
(username, email, firstName, surname, age, password)) #Inserting the user's data into the table
conn.commit() #Committing the changes
conn.close() #Closing the connection
我假设因为主键会自动递增,所以不需要将它添加到代码中,因为每个记录都会自动获得一个数字。问题是,当我回答完所有raw_input
问题时,会收到以下错误消息:
有什么我需要添加到主键的代码中吗?在
我想问题是:
cursor.execute("INSERT INTO users VALUES(?, ?, ?, ?, ?, ?)",
试试这个交换:
^{1}$我认为这个link可以为你解释得更多,我的朋友。在
相关问题 更多 >
编程相关推荐