3

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!

3
  • 1
    ... date_time - what is this supposed to be? add some type to it maybe? dev.mysql.com/doc/refman/5.7/en/datetime.html Commented Oct 24, 2016 at 15:20
  • 1
    Does the query work outside of your python script (against a MySQL instance not SQLite)? Commented Oct 24, 2016 at 15:20
  • I deleted the date_time column and it works great. Thanks!!!!!! Commented Oct 24, 2016 at 15:23

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Type is not added to datetime column..

Change table creation syntax like below.

CREATE TABLE pressure (rowid INT AUTO_INCREMENT NOT NULL, date_time datetime , 
tokyo REAL, primary key (rowid));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.