0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

year_month というカラム名を生クエリで使う時は `` で囲む

0
Last updated at Posted at 2026-09-15

経緯

DB のカラム名に year_month を使ったところ、生クエリでそのまま書くとエラーになった。

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 'year_month' at line 1

前提

  • DB は Docker コンテナ
    • Docker イメージは mysql:8.0
  • pymysql を利用
    requirements.txt
    PyMySQL==1.1.1
    
  • DB 定義変更は prisma migrate dev で反映する

原因

year_month が MySQL 8.0 のキーワードだった。

対応

予約語を ` で囲むように、生クエリを修正する。

SELECT `year_month` FROM foo

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?