Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CREATE TABLE syntax error in mysql 6.3/python 3.5

Tags:

python

mysql

I'm using python to create a table in a mysql 6.3. The code worked great when using sqlite and is now throwing the following error.

pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' tokyo REAL, primary key (rowid))' at line 1")

the code is

import pymysql
conn=pymysql.connect(host='localhost',user='root',password='password',db='testschema',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
a=conn.cursor()
sql='''CREATE TABLE pressure (rowid INT AUTO_INCREMENT NOT NULL, date_time, 
    tokyo REAL, primary key (rowid));'''
a.execute(sql)

Any help is greatly appreciated!

like image 429
Hanley Soilsmith Avatar asked Jun 30 '26 17:06

Hanley Soilsmith


1 Answers

You need to specify the datatype for the date_time column, say DATETIME:

sql='''CREATE TABLE pressure (rowid INT AUTO_INCREMENT NOT NULL, date_time DATETIME, tokyo REAL, primary key (rowid));'''

Reference:

Create Table syntax

like image 111
Moses Koledoye Avatar answered Jul 03 '26 08:07

Moses Koledoye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!