gabucino
gabucino

Reputation: 11

Flask-sqlalchemy does not convert tablenames to lowercase (mysql)

I am trying to create tables in mysql with flask-sqlalchemy. My problem is that the classnames always start with capital letters while I would like to create all tables with lowercase.

Is there a way to fix that? I read that the default behaviour of the flask-sqlalchemy is converting it to lowercase, but it does not seem to work for me.

Thanks for any advice :)

Upvotes: 1

Views: 1107

Answers (2)

CodingMatters
CodingMatters

Reputation: 1431

the default should mape class Name to table 'name'. now I'm curious why your code doesn't. I recently thought my code was not creating the correct tablename only to discover it wasn'it initalising the database correctly due to omitting the database initialisation in my flask server configuration.

https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/table_config.html https://docs.sqlalchemy.org/en/13/orm/mapping_columns.html

Upvotes: 1

dmitrybelyakov
dmitrybelyakov

Reputation: 3864

You can manually define your table names on your models with __tablename__ property.

Upvotes: 1

Related Questions