#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 为 customer_orders 表添加 customer_name 列 """ import sqlite3 import os # 数据库路径 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) DB_PATH = os.path.join(BASE_DIR, 'server', 'data.db') def add_column(): """添加 customer_name 列""" if not os.path.exists(DB_PATH): print(f"错误: 数据库文件不存在: {DB_PATH}") return conn = sqlite3.connect(DB_PATH) c = conn.cursor() try: # 尝试添加列 c.execute('ALTER TABLE customer_orders ADD COLUMN customer_name TEXT') conn.commit() print("成功添加 customer_name 列") except Exception as e: if 'duplicate column name' in str(e).lower(): print("customer_name 列已存在") else: print(f"添加列失败: {e}") conn.close() if __name__ == '__main__': add_column()