Search code examples
pythonpython-3.xkeywordreserved-wordspeewee

Use python keyword as model field in peewee


I am building an ORM for an existing database with peewee in python3.

Now I face the problem in one table, that there is a column named import, which i must introduce as a class' attribute. This, of course does not work that simple because it is a keyword in the python language. Is there a way to change the name of a field in another way? I cannot change the column's name since it will create massive side-effects on other systems.


Solution

  • Use the db_column attribute:

    class MyModel(Model):
        import_ = CharField(db_column='import')