python - SQLAlchemy automatically converts str to unicode on commit -


When putting an object in a database with SQLAlchemy, all of these attributes automatically correspond to the string () column < Type 'str' & gt; & Lt; Type 'Unicode' & gt; Is there any way to stop this behavior?

Here is the code:

  sqlalchemy import from_engine, table, column, integer, string, sqlalchemy.orm import metadata metadata = metadata () table = table (' Projects, Metadata, Column ('id', integer, primary_key = true), mapper, session maker engine = create_agine ('sqlite: ///: memory:', echo = false) column ('name', string (50 )) Class project (object): def __init __ (self, name): self.name = name mapper (project, table) metadata .create_all (engine) in session = session Tax (bind = engine) () Project = Project ("Lorem ipsum") print (type (project.name)) session.add (project) session.commit () print (type (project.name))  

And here's the output:

  & lt; Type 'str' & gt; & Lt; Type 'Unicode' & gt;  

I know that I should probably work with Unicode, but it will involve digging through some third party code and I do not even have Python skills for it :) Actually, one way to do this is to simply execute this line of code after creating the engine. :

engine.raw_connection (). Connection.text_factory = str


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -