如何在Visual Studio烧瓶模板中使用flask_migrate?

时间:2019-04-08 02:07:42

标签: python-3.x visual-studio flask flask-sqlalchemy flask-migrate

我试图将flask_migrate与flask一起使用,但是当我运行我的项目时出现一个错误:需要多个值才能解压。这发生在runserver.py脚本上。我的模型位于其他文件中,但找不到使用Visual Studio模板的教程。这是我的代码。

#runserver.py
from os import environ
from Project import app,db
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand


migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('migrate', MigrateCommand)

if __name__ == '__main__':
    HOST = environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555
    manager.run(HOST, PORT)



#models.py 

from Project import db
from flask_login import UserMixin

class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key= True)
    username = db.Column(db.String(15), unique=True)
    email = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(80))


#settings.py

SECRET_KEY = 'secretjdkjfdjfdk'

SQLALCHEMY_DATABASE_URI = 'sqlite:///demo.db'
SQLALCHEMY_TRACK_MODIFICATIONS = False



# __init__.py 

"""
The flask application package.
"""

from flask import Flask
from Project.settings import SECRET_KEY, SQLALCHEMY_DATABASE_URI, SQLALCHEMY_TRACK_MODIFICATIONS
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.config['SECRET_KEY'] = SECRET_KEY
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = SQLALCHEMY_TRACK_MODIFICATIONS
db = SQLAlchemy(app)


import Project.views
from Project.models import User

0 个答案:

没有答案