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 trialJohn Piaz
1,713 PointsWhy is my .db file not being created?
Why is my .db file not being created? I am using Flask SQLAlchemy, but I am having some problems. Here is my code:
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///test.db'
db = SQLAlchemy(app)
It runs without error, but the .db file is not being created. Any ideas why?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYou are almost there. From the quickstart document page it says:
To create the initial database, just import the db object from an interactive Python shell and run the
SQLAlchemy.create_all() method to create the tables and database:
>>> from yourapplication import db
>>> db.create_all()
So if you above file is called myapp.py you would use: from myapp import db
The db
is the object you created in file myapp.py, line 9
.
Post back if you need more help. Good luck!!