Postingan lainnya
membuat primary key di python 3.7.2 dengan mysql-connector di mysql db
Create primary key when creating the table: script :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
import mysql.connector
mydb = mysql.connector.connect( host="localhost", user="root", passwd="", database="mydatabase" )
mycursor = mydb.cursor()
mycursor.execute(sql = "CREATE TABLE customers (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), address VARCHAR(255))") ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
code erornya : Traceback (most recent call last): File "C:\xampp\htdocs\mypython\testconn.py", line 12, in mycursor.execute(sql = "CREATE TABLE customers (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), address VARCHAR(255))") TypeError: execute() got an unexpected keyword argument 'sql'
Kenapa ya ??
2 Jawaban:
masih tetap eror :: Traceback (most recent call last): File "C:\xampp\htdocs\mypython\testconn.py", line 9, in <module> mycursor.execute("CREATE TABLE customers (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), address VARCHAR(255))") File "C:\Program Files\Python37-32\lib\site-packages\mysql\connector\cursor.py", line 559, in execute self._handle_result(self._connection.cmd_query(stmt)) File "C:\Program Files\Python37-32\lib\site-packages\mysql\connector\connection.py", line 494, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) File "C:\Program Files\Python37-32\lib\site-packages\mysql\connector\connection.py", line 396, in _handle_result raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1050 (42S01): Table 'customers' already exists