ELI5: When I run db.py from CLI, the db.db file is created, but it's 0 KB which makes me think the schema was not created. What can I do to get the model created in the db?
db.py (Edited: 2020-07-22 1007 CST)
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
if __name__ == '__main__':
from app import app
db.init_app(app)
app.app_context().push()
from models import Property
db.create_all()
db.session.commit()
home = Property(
street_address="123 Valentine Dr",
city = "Long Beach",
state = "MS",
postal_code = "39560",
title = "Home"
)
db.session.add(home)
db.session.commit()
models.py (Edited: 2020-07-22 1007 CST)**
from db import db
import datetime
class Property(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(256), nullable=False)
street_address = db.Column(db.String(256), nullable=False)
city = db.Column(db.String(256), nullable=False)
state = db.Column(db.String(256), nullable=False)
postal_code = db.Column(db.String(256), nullable=False)
timestamp = db.Column(db.DateTime, default=datetime.datetime.now)
def __init__(self, title, street_address, city, state, postal_code):
self.title = title
self.street_address = street_address
self.city = city
self.state = state
self.postal_code = postal_code
app.py (Edited: 2020-07-24 12:01 CST)
from flask import Flask, render_template
from ll.ll import ll
app = Flask(__name__)
app.register_blueprint(ll, url_prefix="/ll")
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///db.db"
@app.route("/")
def index():
return render_template("home.html")
if __name__=='__main__':
app.run(debug=True, port="5050")