deutschmarco / sqlautocode

Automatically exported from code.google.com/p/sqlautocode
Other
0 stars 0 forks source link

MySQL - "'ascii' codec can't encode character" with accentuated character in the table name #37

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a table with an accentuated character in the name, like "pdf_imprimé"
2. run sqlautocode

What is the expected output? What do you see instead?
$ sqlautocode mysql://[...]/db -d -e -o model.py
saac.decl - INFO - Reflecting database...
[...]
saac.decl - DEBUG - Creating Model from table: pdf_imprimé
Traceback (most recent call last):
  File "/usr/local/bin/sqlautocode", line 9, in <module>
    load_entry_point('sqlautocode==0.7', 'console_scripts', 'sqlautocode')()
  File "/usr/local/lib/python2.6/dist-packages/sqlautocode/main.py", line 21, in main
    emit(repr(factory))
  File "/usr/local/lib/python2.6/dist-packages/sqlautocode/declarative.py", line 143, in __repr__
    models = self.models
  File "/usr/local/lib/python2.6/dist-packages/sqlautocode/declarative.py", line 192, in models
    self._models.append(self.create_model(table))
  File "/usr/local/lib/python2.6/dist-packages/sqlautocode/declarative.py", line 234, in create_model
    class Temporal(self.DeclarativeBase):
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/ext/declarative.py", line 1336, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/ext/declarative.py", line 1329, in _as_declarative
    **mapper_args)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/__init__.py", line 1116, in mapper
    return Mapper(class_, local_table, *args, **params)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py", line 201, in __init__
    self._configure_properties()
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py", line 851, in _configure_properties
    setparent=True)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py", line 1139, in _configure_property
    prop.instrument_class(self)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/properties.py", line 111, in instrument_class
    doc=self.doc
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/attributes.py", line 1293, in register_descriptor
    manager.instrument_attribute(key, descriptor)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/instrumentation.py", line 182, in instrument_attribute
    self.install_descriptor(key, inst)
  File "/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/instrumentation.py", line 236, in install_descriptor
    setattr(self.class_, key, inst)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 
20: ordinal not in range(128)

What version of the product are you using? On what operating system?
Python 2.6.5 on Linux (I have the same problem with Python 2.7.1 on Windows)
sqlautocode-0.7

Please provide any additional information below.
I also use columns with accentuated characters.

Original issue reported on code.google.com by bigras.b...@gmail.com on 6 Feb 2012 at 3:07

GoogleCodeExporter commented 9 years ago

Hello,
I have the same problem.

In my table, i have colum name with accentuated caracter. It not a problem on a 
classic run. But on declarative mode i have an error.

I think it's a Unicode encode probleme. 

My postgresql base is on utf8 encoding
The psql command for create table in my test db is :

CREATE TABLE "Com"
(
  "Id_GéoFLA" integer,
  "Nom_Commune" character varying(50),
  "Nom_Commune_Min" character varying(50),
  "CodeINSEE" character varying(50),
  "Code_Département" character varying(2),
  "Code_Commune" character varying(3),
  "Code_Canton" integer,
  "Nom_Département" character varying(30),
  "Code_Région" character varying(2),
  "Nom_Région" character varying(30),
  "Nom_Pays" character varying(20)
)

my classic command :

> clasic mode
sqlautocode postgresql+psycopg2://jerome@:0/test --output model_test1.py
>>no error

> declarative mode
sqlautocode postgresql+psycopg2://jerome@:0/test --output model_test2.py -d
>>error description
...
  File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.7.6-py2.7-linux-x86_64.egg/sqlalchemy/orm/instrumentation.py", line 236, in install_descriptor
    setattr(self.class_, key, inst)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: 
ordinal not in range(128)

Original comment by jerome.s...@gmail.com on 4 May 2012 at 8:07

GoogleCodeExporter commented 9 years ago
Same problem for mssql too. 

Original comment by timucink...@gmail.com on 5 Feb 2013 at 1:09