voici mon modele
from django.db import models
from django.contrib.auth.models import BaseUserManager, AbstractUser, PermissionsMixin
from django.contrib.auth.hashers import make_password
from django.conf import settings
from django.utils import timezone
import logging
from django.db import IntegrityError
logger = logging.getLogger(name)
class UserManager(BaseUserManager):
def create_user(self, email, password=None, **extra_fields):
if not email:
raise ValueError(‘The Email field must be set’)
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self.create_user(email, password, **extra_fields)
class User(AbstractUser, PermissionsMixin):
adresse = models.CharField(max_length=100, null=True, blank=True)
matricule = models.CharField(max_length=20, null=True, blank=True)
direction = models.CharField(max_length=50, null=True, blank=True)
email = models.EmailField(unique=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = UserManager()
def __str__(self):
return self.email
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
adresse = models.CharField(max_length=255, blank=True, null=True)
matricule = models.CharField(max_length=50, blank=True, null=True)
direction = models.CharField(max_length=100, blank=True, null=True)
def __str__(self):
return self.user.email
class CanalUSSD(models.Model):
code = models.CharField(max_length=10, unique=True, null=False, blank=False)
description = models.TextField(blank=True)
def __str__(self):
return self.code
class Meta:
verbose_name = "Canal USSD"
verbose_name_plural = "Canaux USSD"
class UseCase(models.Model):
canal = models.ForeignKey(
CanalUSSD,
on_delete=models.SET_NULL, # Changé de PROTECT à SET_NULL
null=True,
blank=True,
related_name=‘usecases’
)
nom = models.CharField(max_length=255)
parent = models.ForeignKey(
‘self’,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name=‘children’
)
numerousecase = models.IntegerField(default=0)
entree = models.CharField(max_length=255)
sortie_attendue = models.TextField()
def __str__(self):
return self.nom
class Meta:
ordering = ['numerousecase']
verbose_name = "Use Case"
verbose_name_plural = "Use Cases"
class TestResult(models.Model):
use_case = models.ForeignKey(
UseCase,
on_delete=models.CASCADE,
related_name=‘test_results’,
null=True,
blank=True
)
date_test = models.DateTimeField(default=timezone.now)
statut = models.CharField(
max_length=10,
choices=[(‘OK’, ‘OK’), (‘NOK’, ‘NOK’)],
null=True,
default=‘OK’
)
message_erreur = models.TextField(blank=True, null=True)
def __str__(self):
use_case_name = self.use_case.nom if self.use_case else "Inconnu"
status = self.statut if self.statut else "Inconnu"
return f"{use_case_name} - {self.date_test.strftime('%Y-%m-%d %H:%M')} - {status}"
class Meta:
ordering = ['-date_test']
verbose_name = "Résultat de test"
verbose_name_plural = "Résultats de tests"
class AlertConfiguration(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name=‘alert_configurations’
)
email = models.EmailField()
canal = models.CharField(max_length=50, blank=True, null=True)
is_active = models.BooleanField(default=True)
def __str__(self):
return f"Alerte pour {self.user.email} ({self.email})"
class Meta:
verbose_name = "Configuration d'alerte"
verbose_name_plural = "Configurations d'alertes"
class Inscription(models.Model):
STATUT_CHOICES = [
(‘en attente’, ‘En attente’),
(‘validé’, ‘Validé’)
]
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
related_name='inscriptions'
)
date_inscription = models.DateTimeField(auto_now_add=True)
statut = models.CharField(
max_length=20,
choices=STATUT_CHOICES,
default='en attente'
)
def __str__(self):
return f"{self.user.email} - {self.statut}"
class Meta:
ordering = ['-date_inscription']
verbose_name = "Inscription"
verbose_name_plural = "Inscriptions"
==============================================================
voici l’erreur que je recois sur toutes les tables de base supprimer ,modifier ,ajouter la meme erreur survient
(env) PS C:\Users\stg_sall86922\Desktop\ProjetDjango> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks…
System check identified some issues:
WARNINGS:
?: (urls.W005) URL namespace ‘admin’ isn’t unique. You may not be able to reverse all URLs in this namespace
System check identified 1 issue (0 silenced).
March 03, 2025 - 21:13:49
Django version 4.2.19, using settings ‘automatisation_app.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /admin/automatisation/usecase/30/change/
Traceback (most recent call last):
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 313, in _commit
return self.connection.commit()
^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.IntegrityError: FOREIGN KEY constraint failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\core\handlers\exception.py”, line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\core\handlers\base.py”, line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\options.py”, line 688, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\decorators.py”, line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\views\decorators\cache.py”,
line 62, in _wrapper_view_func
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\sites.py”, line 242, in inner
return view(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\options.py”, line 1889, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\decorators.py”, line 46, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\decorators.py”, line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\options.py”, line 1746, in changeform_view
with transaction.atomic(using=router.db_for_write(self.model)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\transaction.py”, line 263, in exit
connection.commit()
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\asyncio.py”, line 26,
in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 337, in commit
self._commit()
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 312, in _commit
with debug_transaction(self, “COMMIT”), self.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\utils.py”, line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 313, in _commit
return self.connection.commit()
^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: FOREIGN KEY constraint failed
[03/Mar/2025 21:13:57] “POST /admin/automatisation/usecase/30/change/ HTTP/1.1” 500 134834
[03/Mar/2025 21:15:32] “GET /dashboard/ HTTP/1.1” 200 22468
[03/Mar/2025 21:15:32] “GET /static/images/sonatel.png HTTP/1.1” 304 0
[03/Mar/2025 21:15:43] “GET /dashboard/ HTTP/1.1” 200 22468
Internal Server Error: /admin/automatisation/usecase/30/change/
Traceback (most recent call last):
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 313, in _commit
return self.connection.commit()
^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.IntegrityError: FOREIGN KEY constraint failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\core\handlers\exception.py”, line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\core\handlers\base.py”, line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\options.py”, line 688, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\decorators.py”, line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\views\decorators\cache.py”,
line 62, in _wrapper_view_func
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\sites.py”, line 242, in inner
return view(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\options.py”, line 1889, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\decorators.py”, line 46, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\decorators.py”, line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\contrib\admin\options.py”, line 1746, in changeform_view
with transaction.atomic(using=router.db_for_write(self.model)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\transaction.py”, line 263, in exit
connection.commit()
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\utils\asyncio.py”, line 26,
in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 337, in commit
self._commit()
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 312, in _commit
with debug_transaction(self, “COMMIT”), self.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\utils.py”, line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “C:\Users\stg_sall86922\Desktop\ProjetDjango\env\Lib\site-packages\django\db\backends\base\base.py”, line 313, in _commit
return self.connection.commit()
^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: FOREIGN KEY constraint failed
[03/Mar/2025 21:16:36] “POST /admin/automatisation/usecase/30/change/ HTTP/1.1” 500 134834
Si quelque ici a une solution avant la fin de la nuit suis preneuse s’il vous plait