36 lines
893 B
Python
36 lines
893 B
Python
import os
|
|
import sys
|
|
|
|
# 添加项目根目录到Python路径
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# 设置数据库URL为SQLite
|
|
os.environ['DATABASE_URL'] = 'sqlite:///kamaxitong.db'
|
|
|
|
from app import create_app, db
|
|
from app.models import Admin, Product, Version, License, Device, Ticket
|
|
|
|
# 创建应用实例
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
print("Dropping all tables...")
|
|
db.drop_all()
|
|
|
|
print("Creating all tables...")
|
|
db.create_all()
|
|
|
|
print("Committing changes...")
|
|
db.session.commit()
|
|
|
|
# 验证表创建
|
|
from sqlalchemy import inspect
|
|
inspector = inspect(db.engine)
|
|
tables = inspector.get_table_names()
|
|
print(f"Created tables: {tables}")
|
|
|
|
# 显式关闭数据库连接以确保数据写入磁盘
|
|
db.session.close()
|
|
db.engine.dispose()
|
|
|
|
print("Database initialization completed!") |