14 lines
448 B
Python
14 lines
448 B
Python
|
|
from app import app
|
||
|
|
from extensions import db
|
||
|
|
from sqlalchemy import text
|
||
|
|
|
||
|
|
with app.app_context():
|
||
|
|
try:
|
||
|
|
# 尝试添加 api_key 字段到 users 表
|
||
|
|
db.session.execute(text('ALTER TABLE users ADD COLUMN IF NOT EXISTS api_key VARCHAR(255)'))
|
||
|
|
db.session.commit()
|
||
|
|
print("✅ 数据库字段 users.api_key 同步成功")
|
||
|
|
except Exception as e:
|
||
|
|
db.session.rollback()
|
||
|
|
print(f"❌ 同步失败: {e}")
|