我想使用Python 這裏我的代碼MYSQL和python錯誤
import MySQLdb
#connect to db
db= MySQLdb.connect(host= "localhost",
user="root",
passwd="newpassword",
db="new_schema")
#setup cursor
cursor = db.cursor()
#create anooog1 table
cursor.execute("DROP TABLE IF EXISTS try")
sql = """CREATE TABLE try (
COL1 INT, COL2 INT)"""
cursor.execute(sql)
#insert to table
cursor.execute("""INSERT INTO try VALUES (%s,%s)""",(188,90))
db.commit()
db.rollback()
#show table
cursor.execute("""SELECT * FROM try""")
print cursor.fetchall()
db.close()
插入在MYSQL數據庫中的數據,但錯誤是在我的SQL
Error: `new_schema`.`try`: table data is not editable because there is no primary key defined for the table ...
我該怎麼辦?
你爲什麼這樣做'commit'後'rollback'? – gruszczy 2011-04-19 22:24:07
它有什麼問題? – roro 2011-04-19 22:29:08
如何定義主鍵? – 2011-04-19 22:32:26