/ weekstaat /的OperationalError没有此列:weekstaat_weekstaat.contract_id

时间:2019-06-07 13:45:45

标签: python django django-models

我想在Weekstaat index.html 中使用合同模型中的'organisatie'。

当我在Weekstaat导入合同时,出现此错误:

OperationalError,位于/ weekstaat / 没有这样的列:weekstaat_weekstaat.contract_id。

如何解决此错误?

weekstaat / model.py

from django.db import models
from django.contrib.auth.models import User
from datetime import datetime, date
from contract.models import Contract

...

class Weekstaat(models.Model):
    id = models.AutoField(primary_key=True, null=False, blank=False)
    status = models.CharField(max_length=11, choices=STATUS_CHOICES, default='Niet ingediend',)
    jaar = models.ForeignKey(Jaar, default=datetime.now().year, null=False, blank=False,on_delete=models.CASCADE)
    week = models.ForeignKey(Week, default=date.today().isocalendar()[1], null=False, blank=False,on_delete=models.CASCADE)
    contract = models.ForeignKey(Contract, null=True, blank=False, default=1,on_delete=models.CASCADE)
    werknemer = models.ForeignKey(User, related_name='weekstaat_werknemer', null=False, blank=False, default=1,on_delete=models.CASCADE)
    maandag = models.FloatField(null=True, blank=True, default=0)
    dinsdag = models.FloatField(null=True, blank=True, default=0)
    woensdag = models.FloatField(null=True, blank=True, default=0)
    donderdag = models.FloatField(null=True, blank=True, default=0)
    vrijdag = models.FloatField(null=True, blank=True, default=0)
    zaterdag = models.FloatField(null=True, blank=True, default=0)
    zondag = models.FloatField(null=True, blank=True, default=0)

    def __str__(self):
        return str(self.jaar) + ' week ' + str(self.week) + str(self.werknemer) + str(self.status)

contract / models.py

from django.db import models
from datetime import datetime, timedelta
from django.contrib.auth.models import User
from django.utils import timezone

STATUS_CHOICES = (
    ('actief', 'actief'),
    ('concept', 'concept'),
    ('non-actief', 'non-actief'),
)

class Contract(models.Model):
    id = models.AutoField(primary_key=True, null=False, blank=False)
    organisatie = models.CharField(max_length=145, null=False, blank=False)
    tussenpersoon = models.CharField(max_length=145, null=True, blank=True)
    tussenpersoon_email = models.EmailField(null=True, blank=True)
    persoon = models.ForeignKey(User, null=False, blank=False, default=1, on_delete=models.CASCADE)
    uurtarief = models.FloatField(null=True, blank=True)
    functie = models.CharField(max_length=425, null=True, blank=True)
    begindatum = models.DateField(null=False, blank=False, default=timezone.now)
    einddatum = models.DateField(null=True, blank=True)
    status = models.CharField(max_length=11, choices=STATUS_CHOICES, default='actief')

    def __str__(self):
        return str(self.persoon.email) + ' - ' + str(self.contract.organisatie) + str(self.persoon)

0 个答案:

没有答案