SyntaxError: Invalid character in identifier when importing models generated using sqlacodegen

423 views Asked by At

I am auto-generating tables in postgresql and models are autogenerated using sqlacodegen using names from a list.

Some of the names are non-ascii characters. For name aussieBabe which created a table aussieBabe_index for which sqlAlchemy model is aussieBabeIndex. but when I try to import these models for querying I get below error.

line 147
    class aussieBabeIndex(Base):
                              ^
SyntaxError: invalid character in identifier

I assume that this can be solved by removing invalid characters before creating the table or restricting the class name. I want to restrict the class name which is generated by sqlacodegen, how can i achieve this? or can I set Unicode encoding for code?

1

There are 1 answers

0
Alex Grönholm On BEST ANSWER

Your table name contains some characters which not even Python 3 will allow. You need to fix the class name by hand. SQLACodegen cannot be expected to produce perfect results, as its documentation states too.