Bagaimana menambahkan tabel baru pada tabel yang sudah ada/jadi di mysql dengan python

saya bermaksud menambahkan tabel baru pada tabel yang sudah jadi tetapi kenapa jadi eror?. : If the table already exists, use the ALTER TABLE keyword: Example

Create primary key on an existing table: ##################################################### import mysql.connector

mydb = mysql.connector.connect( host="localhost", user="yourusername", passwd="yourpassword", database: "mydatabase" )

mycursor = mydb.cursor()

mycursor.execute("ALTER TABLE customers ADD COLUMN id INT AUTO INCREMENT PRIMARY KEY") ################################################################################ ini erornya: Traceback (most recent call last): File "C:\xampp\htdocs\mypython\testconn.py", line 9, in mycursor.execute("ALTER TABLE customers ADD COLUMN id INT AUTO INCREMENT PRIMARY KEY") File "C:\Program Files\Python37-32\lib\site-packages\mysql\connector\cursor.py", line 569, in execute self._handle_result(self._connection.cmd_query(stmt)) File "C:\Program Files\Python37-32\lib\site-packages\mysql\connector\connection.py", line 564, 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 453, in _handle_result raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AUTO INCREMENT PRIMARY KEY' at line 1

avatar ahmad710
@ahmad710

14 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Tanggapan

errornya apa coba dituliskan di atas

@ahmad710, mungkin maksud lu nambahin field? check dulu aja itu line 9 koding lu error malih..

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban