Django-fr

Forum

#1 01-03-2017 15:27:20

joyfack
Membre
Inscription : 09-02-2017
Messages : 1

Erreur lors de la migrations

Bonjour,
Je suis débutant dans l'utilisation du FrameWork Django. Pour un projet d'apprentissage j'ai décidé de concevoir une application de Gestion d'une Ecole comprenant des models tel que :Professeur, Matiere, SalleCours et Cours.

""" MATIERE DISPENSES DANS L'ECOLE """
class Matiere(models.Model):
    libMatiere=models.CharField("Libellé Matiére", max_length=50)
    def __str__(self):
        return self.libMatiere

"""Les salles de Classes qui sont dans une Ecole, une classe conrespond à un niveau donné telque 'La Terminal A4 B' """
class SalleClasse (models.Model):
    libClasse=models.CharField("Libellé Classe", max_length=50)
    nbreMax=models.IntegerField("Nombre Maximun Eléve")
    Niveau=models.ForeignKey(Niveau,verbose_name="Niveau Classe")
    def __str__(self):
        return '%s %s %s' % (self.Niveau, self.libClasse, self.nbreMax)


"""Professeur qualifié pour dispenser une ou plusieurs matiére dans l'Ecole"""
class Professeur (models.Model):
    SEX=(
        ('M','M'),
        ('F','F'),
    )
    nomProf=models.CharField("Nom", max_length=50)
    prenomProf=models.CharField("Prénoms", max_length=100)
    dateNaisProf=models.DateField("Date de Naissance")
    sexProf=models.CharField("Sexe", max_length=1, choices=SEX)
    contactProf=models.CharField('Contacts', max_length=20)
    adresseProf=models.TextField("Adresse", max_length=300)
    Matiere=models.ManyToManyField(Matiere, verbose_name="Matiére Dispensées")

    def __str__(self):
        return '%s %s %s %s %s %s' % (self.nomProf, self.prenomProf, self.sexProf, self.dateNaisProf, self.contactProf,
                             self.dateNaisProf)


class Cours(models.Model):
    noteCours=models.IntegerField("Cours Noté sur")
    heureCours=models.IntegerField("Nombre d'heure")
    Matiere=models.ForeignKey(Matiere, verbose_name="Matiére")
    Classe=models.ForeignKey(SalleClasse, verbose_name="Classe")
    Professeur=models.ForeignKey(Professeur, "Professeur")

Quand j'exécute la commande "migrate" il me renvoie une erreur

PS D:\Projects\GestEcole> python manage.py migrate Ecole
Operations to perform:
  Apply all migrations: Ecole
Running migrations:
  Applying Ecole.0005_cours...Traceback (most recent call last):
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 617, in get_field
    return self.fields_map[field_name]
KeyError: 'Professeur'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\operations\models.py", line 96, in database_forwards
    schema_editor.create_model(model)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\schema.py", line 246, in create_model
    definition, extra_params = self.column_sql(model, field)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\schema.py", line 136, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\fields\related.py", line 940, in db_parameters
    return {"type": self.db_type(connection), "check": self.db_check(connection)}
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\fields\related.py", line 937, in db_type
    return self.target_field.rel_db_type(connection=connection)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\fields\related.py", line 855, in target_field
    return self.foreign_related_fields[0]
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\fields\related.py", line 595, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\fields\related.py", line 582, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\fields\related.py", line 575, in resolve_related_fields
    else self.remote_field.model._meta.get_field(to_field_name))
  File "C:\Users\LJ\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 619, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: Professeur has no field named 'Professeur'

Merci d'avance pour vos interventions et conseils

Hors ligne

#2 02-03-2017 07:33:43

Xavier Ordoquy
Administrateur
Lieu : Puteaux, France
Inscription : 12-10-2011
Messages : 296
Site Web

Re : Erreur lors de la migrations

Il n'est pas possible d'aider sans le code de la migration associée.

Hors ligne

Pied de page des forums