SQL in Python is marked with error
已回答
I don't know if this is the right place to report this, just bringing it to someone's attention for PyCharm improvement.
I have this SQL embedded in a Python (3.6) script:
sql = """\
ALTER TABLE token_type auto_increment = 5\
"""
PyCharm indicates an error after the table name, with the message: "'*' or <alter table instruction> expected, got 'auto_increment'. For the record, this is valid (at least for MySQL), to set the auto increment value for a table (as opposed to altering a column to make it an auto increment column).
请先登录再写评论。
Hi Khommel! Which version of PyCharm do you use? Could you please take a screenshot of the error?
Now I’m on Professional 2018.1, build PY-181.4203.547. This problem was happening with the previous version also (2017.3? 2017.4?).
I just had this exact same issue in PHPStorm (2020.2.2) and this seems to be the only search result for this problem.
In my case it turned out that my project was defaulting to my global SQL Dialect, which is PostgreSQL, but this one specific project is MySQL:

So it was displaying an invalid SQL error because AUTO_INCREMENT isn't a valid PostgreSQL statement.
The fix was to set the "Project SQL Dialect" to "MySQL", after that the warning immediately disappeared.
7 Years have passed and this bug still exist. Why is it not fixed? No i can't configure a global or project sql dialect because i use more than one. Visual studio can handle this, why is pycharm so buggy?
Hi Endasil, this issue requires thorough investigation, please create an issue on YouTrack (https://youtrack.jetbrains.com/issues/PY) and attach all relevant information (including IDE logs from Help | Collect Logs and Diagnostic Data) for quicker resolution.