| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/usr/bin/env python3
- """
- Script de migration Django 3.2 → 5.1
- Corrige automatiquement les problèmes de compatibilité
- """
- import os
- import sys
- from pathlib import Path
- def fix_models_file(file_path):
- """Supprime les méthodes __unicode__ dépréciées"""
- print(f"🔧 Correction de {file_path}...")
-
- with open(file_path, 'r', encoding='utf-8') as f:
- content = f.read()
-
- # Supprimer les méthodes __unicode__
- lines = content.split('\n')
- new_lines = []
- skip_next = False
-
- for i, line in enumerate(lines):
- if 'def __unicode__(self):' in line:
- # Ignorer cette ligne et la suivante (return)
- skip_next = True
- continue
- if skip_next:
- skip_next = False
- continue
- new_lines.append(line)
-
- new_content = '\n'.join(new_lines)
-
- with open(file_path, 'w', encoding='utf-8') as f:
- f.write(new_content)
-
- print(f"✅ {file_path} corrigé")
- def main():
- base_dir = Path(__file__).resolve().parent
-
- print("🚀 Début de la migration Django 3.2 → 5.1")
- print("=" * 50)
-
- # Fichiers à corriger
- files_to_fix = [
- base_dir / 'blog' / 'models.py',
- base_dir / 'core' / 'models.py',
- ]
-
- print("\n📝 Correction des fichiers models.py...")
- for file_path in files_to_fix:
- if file_path.exists():
- fix_models_file(file_path)
- else:
- print(f"⚠️ {file_path} introuvable")
-
- print("\n" + "=" * 50)
- print("✅ Migration terminée !")
- print("\n📋 Prochaines étapes :")
- print("1. Activez votre environnement virtuel")
- print("2. Installez les dépendances : pip install -r requirements.txt")
- print("3. Générez une nouvelle SECRET_KEY et mettez à jour .env")
- print("4. Testez les migrations : python manage.py makemigrations")
- print("5. Appliquez les migrations : python manage.py migrate")
- print("6. Lancez le serveur : python manage.py runserver")
- if __name__ == '__main__':
- main()
|