我正在尝试在模型中创建一个ManyToManyField,数据库中的表连接到数据库中的视图。
连接到视图的模型(名为precheck_check)已成功迁移,因此唯一的新代码为applicable_checks = models.ManyToManyFields(Check, related_name = '+')
。
当我尝试使用添加的代码进行迁移时,我得到django.db.utils.ProgrammingError: referenced relation "precheck_check" is not a table"
Models.py 来自 future 导入unicode_literals
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.core.validators import validate_slug,validate_comma_separated_integer_list
from static import validators
class Check(models.Model):
pkey = models.IntegerField(primary_key=True)
cif = models.CharField(max_length=255)
check_name = models.CharField(max_length=255)
description = models.TextField()
class Meta:
managed = False
# Create your models here.
class Job(models.Model):
user = models.ForeignKey('auth.User')
jobID = models.CharField(max_length=50, validators=[validate_slug])
original_file = models.FileField(upload_to='temp',validators = [validators.validate_zip])
rev = models.IntegerField()
create_date = models.DateTimeField(default=timezone.now)
file_name = models.CharField(max_length=255, null = True)
applicable_checks = models.ManyToManyField(Check, related_name = '+')
def save(self):
last_rev = Job.objects.filter(user_id=self.user_id).filter(jobID=self.jobID).order_by('-rev')
if last_rev:
self.rev = last_rev[0].rev + 1
else:
self.rev = 1
super(Job,self).save()
def __unicode__(self):
return self.jobID + " rev " + str(self.rev)
class Meta:
indexes = [
models.Index(fields=['user','jobID']),
]
unique_together = ("user","jobID","rev")
ordering = ['-create_date']
get_latest_by = 'create_date'
我哪里错了?