Canedje
Posts: 265
Joined: Thu Mar 26, 2015 7:18 am

mysql error 1054

Mon Apr 06, 2015 10:11 am

I'm busy trying to use a MSQL database.
I'm able to create a table:

Code: Select all

CREATE TABLE p1uitlezen (date DATE, time TIME, t1afverm INT(5), t2afverm INT(5), t1terugverm INT(5), t2terugverm INT(5), afverm INT(5), terugverm INT(5));
In Python I do try to fill it in this way:

Code: Select all

con = mdb.connect('127.0.0.1', 'pi', 'raspberry', 'p1db');


try:

        with con:
                cur = con.cursor()
                cur.execute("INSERT INTO p1uitlezen(date, time, t1afverm, t2afverm, t1terugverm, t2terugverm, afverm, terugverm) VALUES(stdate, sttime, T1afverm, T2afverm, T1terugverm, T2terugverm, bewgetal, bewgetal1)")
                con.commit()
except mdb.Error, e:

    if con:
        con.rollback()

    print "Error %d: %s" % (e.args[0],e.args[1])
    sys.exit(1)

finally:

    if con:
        con.close()

At execute I do receive this error:
Error 1054: Unknown column 'stdate' in 'field list'

What am I doing wrong?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: mysql error 1054

Mon Apr 06, 2015 10:29 am

Rename your date & time columns. It's a very bad idea to use SQL reserved words for column names. If it doesn't hurt now it could break with ANY future version of the database manager software.

Else where you've used a reserved word enclose it in quotes or aposts to avoid the problem. This isn't foolproof as a future release may still break it.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Canedje
Posts: 265
Joined: Thu Mar 26, 2015 7:18 am

Re: mysql error 1054

Mon Apr 06, 2015 12:48 pm

DougieLawson wrote:Rename your date & time columns. It's a very bad idea to use SQL reserved words for column names. If it doesn't hurt now it could break with ANY future version of the database manager software.

Else where you've used a reserved word enclose it in quotes or aposts to avoid the problem. This isn't foolproof as a future release may still break it.
Thanks for the answer.
I changed time and date in mytime and mydate.

Still the same error occurs?
the stdate format is:
stdate : 06-04-2015
sttime : 14:47:46

Canedje
Posts: 265
Joined: Thu Mar 26, 2015 7:18 am

Re: mysql error 1054

Mon Apr 06, 2015 8:09 pm

After hours and hours trying I do have the solution
I'm able to fill the mysql table

Return to “Troubleshooting”