File tree 1 file changed +9
-0
lines changed 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ Here the example `database.py` module for your application::
47
47
Base.query = db_session.query_property()
48
48
49
49
def init_db():
50
+ # import all modules here that might define models so that
51
+ # they will be registered properly on the metadata. Otherwise
52
+ # you will have to import them first before calling init_db()
53
+ import yourapplication.models
50
54
Base.metadata.create_all(bind=engine)
51
55
52
56
To define your models, just subclass the `Base ` class that was created by
@@ -84,6 +88,11 @@ Here is an example model (put this into `models.py`, e.g.)::
84
88
def __repr__(self):
85
89
return '<User %r>' % (self.name)
86
90
91
+ To create the database you can use the `init_db ` function:
92
+
93
+ >>> from yourapplication.database import init_db
94
+ >>> init_db()
95
+
87
96
You can insert entries into the database like this:
88
97
89
98
>>> from yourapplication.database import db_session
You can’t perform that action at this time.
0 commit comments