Bonjour,
Je travaille avec Django 1.9 et j'ai un souci avec ma base de données :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | OperationalError at /admin/projects/project/ no such column: projects_project.progression_id Request Method: GET Request URL: http://127.0.0.1:8000/admin/projects/project/ Django Version: 1.9.1 Exception Type: OperationalError Exception Value: no such column: projects_project.progression_id Exception Location: /home/vincent/.local/share/virtualenvs/dcb/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py in execute, line 323 Python Executable: /home/vincent/.local/share/virtualenvs/dcb/bin/python Python Version: 3.5.1 Python Path: ['/home/vincent/Documents/ensimag/nsigma/etudes/DCB/DCB-Web', '/home/vincent/.local/share/virtualenvs/dcb/lib/python35.zip', '/home/vincent/.local/share/virtualenvs/dcb/lib/python3.5', '/home/vincent/.local/share/virtualenvs/dcb/lib/python3.5/plat-linux', '/home/vincent/.local/share/virtualenvs/dcb/lib/python3.5/lib-dynload', '/usr/lib64/python3.5', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-linux', '/home/vincent/.local/share/virtualenvs/dcb/lib/python3.5/site-packages'] Server time: ven, 12 Fév 2016 20:45:00 +0100 |
Mes modèles ont ces têtes :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | import os.path from django.db import models from django.core.validators import MinValueValidator, MaxValueValidator from django.utils.timezone import now from django.conf import settings from autoslug import AutoSlugField def project_background_path(instance, filename): return 'projects/backgrounds/{}{}'.format(instance.slug, os.path.splitext(filename)[1]) def cap_progression_path(instance, filename): return 'projects/cap/{}{}'.format(instance.slug, os.path.splitext(filename)[1]) def image_media_path(instance, filename): return 'projects/media/images/{}{}'.format(instance.id, os.path.splitext(filename)[1]) class Progression(models.Model): numerical = models.PositiveSmallIntegerField( default=0, validators=[MaxValueValidator(settings.MAX_PROGRESSION)], verbose_name='Progression numérique' ) cap = models.ImageField( null=True, blank=True, upload_to=cap_progression_path, verbose_name='Progression CAP', ) class Project(models.Model): correspondent = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name='Correspondant', ) name = models.CharField( max_length=settings.PROJECT_NAME_MAX_LEN, verbose_name='Nom', ) slug = AutoSlugField(populate_from='name', unique=True) creation_date = models.DateField( null=True, blank=True, verbose_name='Date de création', ) background_image_height = models.PositiveSmallIntegerField( null=True, blank=True, ) background_image_width = models.PositiveSmallIntegerField( null=True, blank=True, ) background_image = models.ImageField( null=True, blank=True, upload_to=project_background_path, height_field='background_image_height', width_field='background_image_width', verbose_name="Image d'arrière-plan", ) theoretical_duration = models.DurationField( null=True, blank=True, verbose_name='Durée théorique', ) latitude = models.FloatField( null=True, blank=True, validators=[ MinValueValidator(settings.MIN_LAT), MaxValueValidator(settings.MAX_LAT), ] ) longitude = models.FloatField( null=True, blank=True, validators=[ MinValueValidator(settings.MIN_LNG), MaxValueValidator(settings.MAX_LNG), ] ) description = models.TextField(default='', blank=True) progression = models.ForeignKey( Progression, on_delete=models.CASCADE, related_name='progression', verbose_name='Progression', blank=True, null=True, ) proposed_progression = models.ForeignKey( Progression, on_delete=models.CASCADE, related_name='proposed_progression', verbose_name='Progression proposée', blank=True, null=True, ) in_validation = models.BooleanField(default=False, verbose_name='En validation',) validated = models.BooleanField(default=False, verbose_name='Validé',) archived = models.BooleanField(default=False, verbose_name='Archivé',) def __str__(self): return self.name |
Un projet dispose d'une progression, laquelle peut être numérique ou sous forme d'image. A l'instar de ZdS, il est possible de mettre à jour la progression du projet en passant par une phase de validation, c'est pourquoi j'ai un second attribut (proposed_progression
).
Sauf que je ne parviens pas à créer un projet sur l'interface d'administration. J'ai pourtant, dans un élan de fureur incoercible, exécuté les commandes suivantes :
1 2 3 4 5 | $ rm -rf projects/migrations $ python manage.py flush $ python manage.py makemigrations projects $ python manage.py migrate $ python manage.py createsuperuser |
Merci.
PS : au passage, je ne comprends pas pourquoi il m'embête sur les deux attributs de progression et m'oblige à spécifier related_name
.
+0
-0