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?

SQLAlchemyを使って勉強する機会があって、つまづいたときのメモです。

1.Booleanを扱いたい(エラーなく通ったコード)

def insert_event():
  DB_URI = "~~"
  db_engine = create_engine(DB_URI,  pool_pre_ping=True, echo=True)
  setup_db(db_engine)
  with create_session(db_engine) as ssn:
    with ssn.begin():
      incident = Incident()
      incident.system_name = "勘定"
      incident.incident_flg = False
      ssn.add(incident)
insert_event()

2.間違った指定方法
String扱いになる書き方をしていた。

   incident.incident_flg = "False"
   incident.incident_flg = "0"

このときのエラー

   raise TypeError("Not a boolean value: %r" % (value,))
   sqlalchemy.exc.StatementError: (builtins.TypeError) Not a boolean value: 'False'
   raise TypeError("Not a boolean value: %r" % (value,))
   sqlalchemy.exc.StatementError: (builtins.TypeError) Not a boolean value: '0'
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?