"_sqlite3_column_type",referenced from

本文介绍了一种在接手旧项目时遇到的特定错误,并提供了解决该问题的方法:通过添加缺失的libsqlite3.0.tbd文件来修复错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一,说明

在接收旧项目时,报错如下:


二:解决方法(缺少文件,添加libsqlite3.0.tbd)









from graphviz import Digraph import pymysql # 1. 连接数据库(需替换实际配置) conn = pymysql.connect( host=&#39;localhost&#39;, user=&#39;root&#39;, password=&#39;your_password&#39;, database=&#39;your_database&#39;, charset=&#39;utf8mb4&#39; # 确保字符集支持中文注释 ) cursor = conn.cursor() # 2. 初始化Graphviz dot = Digraph(comment=&#39;课堂行为系统 ER 图&#39;, format=&#39;png&#39;) dot.attr(rankdir=&#39;LR&#39;, nodesep=2, ranksep=1.5) # 优化布局参数 # 3. 获取所有表及其列信息(含主键和外键标记) def get_table_info(): cursor.execute("SHOW FULL TABLES") tables = [table[0] for table in cursor.fetchall()] table_info = {} for table in tables: # 获取主键 cursor.execute(f"SHOW KEYS FROM `{table}` WHERE Key_name = &#39;PRIMARY&#39;") primary_keys = [row[2] for row in cursor.fetchall()] # 获取外键信息 cursor.execute(f""" SELECT COLUMN_NAME as fk_column, REFERENCED_TABLE_NAME as ref_table, REFERENCED_COLUMN_NAME as ref_column FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = &#39;{table}&#39; AND REFERENCED_TABLE_NAME IS NOT NULL """) foreign_keys = cursor.fetchall() # 获取普通列 cursor.execute(f"SHOW COLUMNS FROM `{table}`") columns = [] for col in cursor.fetchall(): col_name = col[0] col_type = col[1] comment = col[4] # 构建列信息 column_label = f"{col_name} : {col_type}" if comment: column_label += f" ({comment})" # 标记主键 if col_name in primary_keys: column_label = f"<b>{col_name}</b> (PK) : {col_type}" if comment: column_label += f" ({comment})" # 添加到列信息 columns.append((col_name, column_label)) table_info[table] = { &#39;primary&#39;: primary_keys, &#39;foreign_keys&#39;: foreign_keys, &#39;columns&#39;: columns } return table_info # 4. 生成实体节点 table_info = get_table_info() for table, info in table_info.items(): # 按主键优先排序 sorted_columns = sorted( info[&#39;columns&#39;], key=lambda x: x[0] not in info[&#39;primary&#39;] # 主键排前面 ) # 构建HTML表格 column_labels = [col[1] for col in sorted_columns] label = f"""<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD BGCOLOR="#EEEEFF"><B>{table}</B></TD></TR> {&#39;&#39;.join([f&#39;<TR><TD>{label}</TD></TR>&#39; for label in column_labels])} </TABLE>>""" dot.node(table, label=label, shape=&#39;none&#39;) # 5. 生成关系边 existing_relations = set() # 避免重复关系 for table, info in table_info.items(): for fk in info[&#39;foreign_keys&#39;]: fk_column, ref_table, ref_column = fk # 关系唯一标识(表A-表B) relation_key = (ref_table, table) if relation_key in existing_relations: continue # 已处理过反向关系 existing_relations.add(relation_key) # 确定关系类型 if len(info[&#39;primary&#39;]) == 1 and any(ref_column == rpt[2] for rpt in table_info[ref_table][&#39;foreign_keys&#39;]): cardinality = &#39;1:N&#39; # 双向1:N关系 else: cardinality = &#39;N:M&#39; # 默认多对多 # 创建关系节点 rel_label = f"{table}→{ref_table} ({cardinality})" dot.node(rel_label, label=rel_label, shape=&#39;diamond&#39;, color=&#39;gray&#39;) # 建立连接 dot.edge(table, rel_label) dot.edge(rel_label, ref_table) # 6. 保存ER图 dot.render(&#39;classroom_behavior_er&#39;, view=True) # 7. 关闭连接 cursor.close() conn.close() 运行代码
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值