Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python SQLAlchemy Basics Introduction to SQLAlchemy Creating a Model

Base.metadata.create_all(engine)

would this work to create just the users table?

User.metadata.create_all(engine)

if not, how would I do that?

Best,

Jaeson

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Hey jaesonshin, good question! According to the create_all docs, the parameter tables may list the tables to create. Default is None where all would be created.

Try Base.metadata.create_all(tables=[User])

Doc entry:

sqlalchemy.schema.MetaData.create_all(bind=None, tables=None, checkfirst=True)

Create all tables stored in this metadata.

Conditional by default, will not attempt to recreate tables already present in the target database.

Parameters

bind – A Connectable used to access the database; if None, uses the existing bind on this MetaData, if any.

tables – Optional list of Table objects, which is a subset of the total tables in the MetaData (others are ignored).

checkfirst – Defaults to True, don’t issue CREATEs for tables already present in the target database.

Oh.. I should have read the documentation more carefully... Thanks for putting up with this :)