I am trying to create the tables for my models, which are defined in a separate module from my app. I call db.create_all()
, but no tables are created and there are no errors. I've defined the models and imported them before calling create_all
. Why doesn't this work?
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:123@localhost/flask'
db = SQLAlchemy(app)
from models import User
db.create_all()
db.session.commit()
models.py
:
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class User(db.Model):
__tablename__ = 'users'
uid = db.Column(db.Integer, primary_key = True)