P
P
pcdesign2015-01-08 20:45:32
MySQL
pcdesign, 2015-01-08 20:45:32

Why does sqlacodegen generate tables in the form of classes for some Mysql tables, and for other tables in the form of Tables?

There is sqlacodegen module
https://pypi.python.org/pypi/sqlacodegen/1.1.4
Which generates code for further use in SQLAlchemy.

Some tables, it generates like this:

class User(Base):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128))


And some tables look like this:

t_users_forum = Table(
    'users_forum', metadata,
    Column('id', Integer, nullable=False),
    Column('login', String(25), nullable=False),
)


Why is this happening? Why does he represent one table in the form of classes, but not the other.
And how to make any table from MySQL generated as classes?

PS: I tried to read the source code:
https://bitbucket.org/agronholm/sqlacodegen/src/99...
But, I can't understand the logic without half a liter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Ozeransky, 2015-01-08
@pcdesign

Lines 532-537

# Only form model classes for tables that have a primary key and are not association tables
            if not table.primary_key or table.name in association_tables:
                model = ModelTable(table)
            else:
                model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
                classes[model.name] = model

because of the primary key.
add primary keys accordingly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question