Here's my file structure:
/
/apitestproject
/models
__init__.py
users.py
items.py
/resources
__init__.py
users.py
items.py
__init__.py
index.py
.deployment
deploy.cmd
requirements.txt
run_waitress_server.py
runserver.py
web.config
Inside my main __init__.py file I have:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
POSTGRES = {
'user': 'admin_user@pracap',
'pw': 'the_password',
'db': 'apitest',
'host': 'pracap.postgres.database.azure.com',
'port': '5432',
}
URL = 'postgresql://{}:{}@{}:{}/{}'.format(POSTGRES['user'], POSTGRES['pw'], POSTGRES['host'], POSTGRES['port'], POSTGRES['db'])
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = URL
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
import apitestproject.index
In my index.py file I have:
from flask import Flask
from flask_restful import Api
from apitestproject import app, db
@app.before_first_request
def create_tables():
db.create_all()
@app.route('/')
@app.route('/home')
def home():
return "I'm the default route"
And in my /models/users.py file i have:
from apitestproject import db
class UserModel(db.Model):
__tablename__ = 'users'
id = db.column(db.string, primary_key=True)
name = db.column(db.string(50))
address = db.column(db.string(144))
salary = db.column(db.numeric(12, 2))
position = db.column(db.string(50))
password = db.column(db.string(50))
The console is not throwing any errors and I can run everything right without even a single hint of an error. But the tables are not created. Any idea what I might be doing wrong? I've been working with flask/sqlalchemy for just over a month now and I'm starting to work with DB's.
Any help would be appreciated!