Skip to content

How to use databases.Database() with sqlalchemy.Table.create(engine) #400

Answered by aminalaee
bobbetter asked this question in Q&A
Discussion options

You must be logged in to vote

So you want to create SQLAlchemy table?
There are some examples in orm repository which use databases.
Sorry I'm on phone, I will send an example later.

Update:

import databases
import sqlalchemy

database = databases.Database("sqlite:///db.sqlite")
metadata = sqlalchemy.MetaData()


Table('my_table', metadata,
    Column('id', Integer, primary_key=True),
    Column('name', String(50))
)

engine = sqlalchemy.create_engine(str(database.url))
metadata.create_all(engine)

Something along these lines should work.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@bobbetter
Comment options

@aminalaee
Comment options

@bobbetter
Comment options

Answer selected by bobbetter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants