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 ??

avatar ahmad710
@ahmad710

14 Kontribusi 0 Poin

Diperbarui 5 tahun yang lalu

2 Jawaban:

Gak usah pakai sql, langsung aja create table

avatar bosque
@bosque

187 Kontribusi 104 Poin

Dipost 5 tahun yang lalu

Tanggapan

masih eror ini erornya dibawah:

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

avatar ahmad710
@ahmad710

14 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban