36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
"""
|
|
修复 django_migrations 表中的旧 app 名称引用。
|
|
在服务器上执行: python manage.py shell < fix_migration_history.py
|
|
或: python manage.py shell
|
|
然后粘贴此脚本内容
|
|
"""
|
|
from django.db import connection
|
|
|
|
APP_NAME_MAPPINGS = {
|
|
'houtai': 'backend',
|
|
'yonghu': 'users',
|
|
'dingdan': 'orders',
|
|
'peizhi': 'config',
|
|
'shangpin': 'products',
|
|
'shangdian': 'shop',
|
|
'dengji': 'rank',
|
|
}
|
|
|
|
with connection.cursor() as cursor:
|
|
for old_name, new_name in APP_NAME_MAPPINGS.items():
|
|
cursor.execute(
|
|
"SELECT COUNT(*) FROM django_migrations WHERE app = %s",
|
|
[old_name]
|
|
)
|
|
count = cursor.fetchone()[0]
|
|
if count > 0:
|
|
cursor.execute(
|
|
"UPDATE django_migrations SET app = %s WHERE app = %s",
|
|
[new_name, old_name]
|
|
)
|
|
print(f"已更新 {count} 条记录: {old_name} -> {new_name}")
|
|
else:
|
|
print(f"无需更新: {old_name} (无记录)")
|
|
|
|
print("\n修复完成!请运行 python manage.py migrate")
|