mysql-connector-python で、  
datetime フィールド１つだけinsertしようとすると  
prepareエラーで登録できません。

  * mysql-connector-python VERSION

```

    grep VERSION /usr/local/lib/python3.8/dist-packages/mysql/connector/version.py
    VERSION = (8, 0, 20, '', 1)
    
```

  * MySQLテーブル

```

    create table t(
      id int primary key auto_increment,
      dt datetime
    ) engine = InnoDB"
    
```

  * python

```

    # これは成功する
    s1 = "insert into t(id, dt) values (%s, %s)"
    v1 = (1, datetime.datetime.strptime('2000-01-01', "%Y-%m-%d"))
    cursor.execute(s1, v1)
    
    
    # こっちは失敗する
    s2 = "insert into t(dt) values (%s)"
    v2 = (datetime.datetime.strptime('2000-01-01', "%Y-%m-%d"))
    cursor.execute(s2, v2)
    
```

  * エラー内容

```

    Traceback (most recent call last):
      File ".../t.py", line 17, in <module>
        cursor.execute(s2, v2)
      File "/usr/local/lib/python3.8/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute
        prepared = self._cnx.prepare_for_mysql(params)
      File "/usr/local/lib/python3.8/dist-packages/mysql/connector/connection_cext.py", line 632, in prepare_for_mysql
        raise ValueError("Could not process parameters")
    ValueError: Could not process parameters
    
```

  * 暫定対応

```

    # prepare辞める
    s2 = "insert into t(dt) values ('%s')" % ('2000-01-01')
    cursor.execute(s2)
    
```
CC BY-SA 4.0
2020-06-15T13:30:31.757
67692
2020-06-20T23:27:34.853
26568
question
python python3 mysql
mysql-connector-python の datetime フィールドprepareエラー
自己解決  
パラメータが１個の時、カンマの追加が必須でした。

```

    v2 = (datetime.datetime.strptime('2000-01-01', "%Y-%m-%d"),)
    
```
CC BY-SA 4.0
2020-06-20T23:27:34.853
67848
2020-06-20T23:27:34.853
26568
67692
answer