在使用flask创建数据库时,当我执行db.create_all()
时,不是形成数据库文件,而是形成纯文本空文件。我正在使用flask,sqlalchemy orm和sqlite3作为数据库。我的init.py文件包含此文件...
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
import os
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'main.sqlite')
db = SQLAlchemy(app)
ma = Marshmallow(app)
from main import route
答案 0 :(得分:0)
尝试更改
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'main.sqlite')
到
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'main.db')