add fix catch en
This commit is contained in:
		
							
								
								
									
										25
									
								
								backend/_oneoff_fix_all_migrations.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								backend/_oneoff_fix_all_migrations.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| import os | ||||
| import sys | ||||
|  | ||||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') | ||||
|  | ||||
| try: | ||||
|     import django | ||||
|     django.setup() | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Django setup failed: {e}") | ||||
|     sys.exit(1) | ||||
|  | ||||
| from django.db import connection | ||||
|  | ||||
| try: | ||||
|     with connection.cursor() as c: | ||||
|         # Clear all migration history to start fresh | ||||
|         c.execute("DELETE FROM django_migrations") | ||||
|         deleted = c.rowcount | ||||
|     connection.commit() | ||||
|     print(f"[OK] Cleared all migration history: {deleted} rows deleted") | ||||
|     sys.exit(0) | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Failed to clear migration history: {e}") | ||||
|     sys.exit(2) | ||||
							
								
								
									
										28
									
								
								backend/_oneoff_fix_auth.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								backend/_oneoff_fix_auth.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| import os | ||||
| import sys | ||||
|  | ||||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') | ||||
|  | ||||
| try: | ||||
|     import django | ||||
|     django.setup() | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Django setup failed: {e}") | ||||
|     sys.exit(1) | ||||
|  | ||||
| from django.db import connection | ||||
|  | ||||
| try: | ||||
|     with connection.cursor() as c: | ||||
|         c.execute( | ||||
|             "DELETE FROM django_migrations WHERE app=%s AND name=%s", | ||||
|             ["auth", "0001_initial"], | ||||
|         ) | ||||
|         deleted = c.rowcount | ||||
|     connection.commit() | ||||
|     print(f"[OK] Deleted rows in django_migrations for auth: {deleted}") | ||||
|     sys.exit(0) | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Failed to fix auth migration history: {e}") | ||||
|     sys.exit(2) | ||||
|  | ||||
							
								
								
									
										42
									
								
								backend/_oneoff_fix_auth_many.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								backend/_oneoff_fix_auth_many.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| import os | ||||
| import sys | ||||
|  | ||||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') | ||||
|  | ||||
| try: | ||||
|     import django | ||||
|     django.setup() | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Django setup failed: {e}") | ||||
|     sys.exit(1) | ||||
|  | ||||
| from django.db import connection | ||||
|  | ||||
| NAMES = ( | ||||
|     '0002_alter_permission_name_max_length', | ||||
|     '0003_alter_user_email_max_length', | ||||
|     '0004_alter_user_username_opts', | ||||
|     '0005_alter_user_last_login_null', | ||||
|     '0006_require_contenttypes_0002', | ||||
|     '0007_alter_validators_add_error_messages', | ||||
|     '0008_alter_user_username_max_length', | ||||
|     '0009_alter_user_last_name_max_length', | ||||
|     '0010_alter_group_name_max_length', | ||||
|     '0011_update_proxy_permissions', | ||||
|     '0012_alter_user_first_name_max_length', | ||||
| ) | ||||
|  | ||||
| try: | ||||
|     with connection.cursor() as c: | ||||
|         c.executemany( | ||||
|             "DELETE FROM django_migrations WHERE app=%s AND name=%s", | ||||
|             [("auth", n) for n in NAMES], | ||||
|         ) | ||||
|         deleted = c.rowcount | ||||
|     connection.commit() | ||||
|     print(f"[OK] Deleted rows for auth:* : {deleted}") | ||||
|     sys.exit(0) | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Failed to batch delete auth migrations: {e}") | ||||
|     sys.exit(2) | ||||
|  | ||||
							
								
								
									
										29
									
								
								backend/_oneoff_fix_contenttypes.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								backend/_oneoff_fix_contenttypes.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| import os | ||||
| import sys | ||||
|  | ||||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') | ||||
|  | ||||
| try: | ||||
|     import django | ||||
|     django.setup() | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Django setup failed: {e}") | ||||
|     sys.exit(1) | ||||
|  | ||||
| from django.db import connection | ||||
|  | ||||
| try: | ||||
|     with connection.cursor() as c: | ||||
|         # Remove the incorrect history row if it exists | ||||
|         c.execute( | ||||
|             "DELETE FROM django_migrations WHERE app=%s AND name=%s", | ||||
|             ["contenttypes", "0002_remove_content_type_name"], | ||||
|         ) | ||||
|         deleted = c.rowcount | ||||
|     connection.commit() | ||||
|     print(f"[OK] Deleted rows in django_migrations: {deleted}") | ||||
|     sys.exit(0) | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Failed to fix migration history: {e}") | ||||
|     sys.exit(2) | ||||
|  | ||||
							
								
								
									
										33
									
								
								backend/_oneoff_fix_contenttypes_table.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								backend/_oneoff_fix_contenttypes_table.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| import os | ||||
| import sys | ||||
|  | ||||
| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') | ||||
|  | ||||
| try: | ||||
|     import django | ||||
|     django.setup() | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Django setup failed: {e}") | ||||
|     sys.exit(1) | ||||
|  | ||||
| from django.db import connection | ||||
|  | ||||
| try: | ||||
|     with connection.cursor() as c: | ||||
|         # Check if name column exists | ||||
|         c.execute("SHOW COLUMNS FROM django_content_type LIKE 'name'") | ||||
|         has_name = c.fetchone() | ||||
|          | ||||
|         if has_name: | ||||
|             print("[INFO] 'name' column exists, removing it...") | ||||
|             c.execute("ALTER TABLE django_content_type DROP COLUMN name") | ||||
|             print("[OK] Removed 'name' column from django_content_type") | ||||
|         else: | ||||
|             print("[INFO] 'name' column does not exist, table is already correct") | ||||
|              | ||||
|     connection.commit() | ||||
|     print("[OK] django_content_type table structure fixed") | ||||
|     sys.exit(0) | ||||
| except Exception as e: | ||||
|     print(f"[ERROR] Failed to fix django_content_type table: {e}") | ||||
|     sys.exit(2) | ||||
		Reference in New Issue
	
	Block a user
	 unknown
					unknown