使用Django 1.9.1并使用托管Postgres db(版本9.4.5)的Vagrant VM(Debian / Jessie64)进行测试。
我已经开始草绘我的模型并且网站运行正常 - 通过Admin界面添加记录很好等,但每次我尝试运行最基本的测试时,我收到以下错误:< / p>
django.db.utils.ProgrammingError: relation "contacts_person" does not exist
LINE 1: ...ion_id", "contacts_person"."directed_person" FROM "contacts_...
models.py:
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=50)
organisation = models.ForeignKey('contacts.Organisation', on_delete=models.CASCADE, null=True, blank=True)
directed_person = models.BooleanField(default=True)
def __str__(self):
return '%s %s'% (self.first_name, self.last_name)
class Mode(models.Model):
mode = models.CharField(max_length=50, blank=False)
def __str__(self):
return self.mode
class OrgType(models.Model):
type = models.CharField(max_length=15)
mode = models.ForeignKey('contacts.Mode', on_delete=models.CASCADE)
def __str__(self):
return self.type
class Organisation(models.Model):
name = models.CharField(max_length=100, null=False)
[--fields--]
def __str__(self):
return self.name
我在这个阶段的测试很简单:
class ModelCreationTests(TestCase):
def setUp(self):
Person.objects.create(first_name='Kimo', last_name='Rance', organisation=1, directed_person=True)
Organisation.objects.create(
name = 'Orgname',
type = 'Orgtype',
[--fields, etc--]
)
def test_is_a_person(self):
p = Person()
self.assertIsInstance(p, Person)
我已经看到Googling对此的历史引用表明它可能是早期版本的Django中的一个错误,特别是对于PostgreSQL,但似乎找不到合理的解决方案。任何进一步的帮助非常感谢。
包含来自./manage.py的输出--verbosity = 2 在knbk评论之后:
Operations to perform:
Apply all migrations: contenttypes, contacts, sessions, admin, auth
Running pre-migrate handlers for application admin
Running pre-migrate handlers for application auth
Running pre-migrate handlers for application contenttypes
Running pre-migrate handlers for application sessions
Running pre-migrate handlers for application bootstrap3
Running pre-migrate handlers for application contacts
Running migrations:
No migrations to apply.
Running post-migrate handlers for application admin
Running post-migrate handlers for application auth
Running post-migrate handlers for application contenttypes
Running post-migrate handlers for application sessions
Running post-migrate handlers for application bootstrap3
Running post-migrate handlers for application contacts
在向模型添加字段时尝试时类似。似乎不是问题。