What type is used to store byte strings in SQLAlchemy?

I am trying to save byte strings in a PostgreSQL database using SQLAlchemy.

My model looks like this:

class UserAccount(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String) password_hash = db.Column(db.String) password_salt = db.Column(db.String) 

I want password_hash and password_salt both to be byte strings (i.e. str since I use Python 2.7), but even if I pass bytes to it, SQLAlchemy seems to turn them into unicode. I also tried using convert_unicode=False in the model, but I get the same result.

What can I use to store bytes in the SQLAlchemy model?

+5
source share
1 answer

Use LargeBinary , which will use bytea on PostgreSQL. You can also use the bytea type if you intend to use PostgreSQL.

+8
source

Source: https://habr.com/ru/post/1207919/


All Articles