Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Tags:

mysql

Could someone please tell me why I am getting this error and what I should change!

mysql_exceptions.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 'ORDER int,\n
FOREIGN KEY (ID) REFERENCES papers(ID),\n PRIMARY K' at line 4")

This is my statement:

""" CREATE TABLE Authors (
    ID        int NOT NULL,
    AUTHOR   varchar(255),
    ORDER     int,
    FOREIGN KEY (ID) REFERENCES papers(ID),
    PRIMARY KEY (ID, ORDER)
    ) """

Thank you I am new to sql and simply cannot spot where I have gone wrong!

like image 815
Paul Smith Avatar asked Dec 05 '25 05:12

Paul Smith


1 Answers

"ORDER" is a reserved word and cannot be used as a field name...

Select * from Author order by order;

https://dev.mysql.com/doc/refman/5.5/en/keywords.html

If you absolutely want to use order as a field name, you must quote it, but it is better to avoid it, since you also would need to quote it in any sql sentence refering it.

like image 61
MortenSickel Avatar answered Dec 07 '25 19:12

MortenSickel