我使用的是Python 3.4和Django 1.9.1,我试图迁移我的新模型。首先我写下:在命令提示符下运行python manage.py makemigrations任务,并且没有问题。但后来我输入:Python的Django 1.9迁移错误'错误创建新的内容类型...'
蟒蛇manage.py迁移任务
但我不断收到有关CONTENTTYPES此错误:
“错误创建新的内容类型。请确保在尝试单独迁移应用程序之前迁移contenttypes'
我试着在类似的stackoverflow问题中四处寻找,但没有任何帮助。我如何得到这个错误停止? Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually的一个这样的解决方案声明:
通过手动删除'django_content_type'表中的列名称。例如。
'ALTER TABLE django_content_type DROP列名'
但我怎么做呢?到目前为止,我还没有想出如何在Django中使用像这样的纯SQL语句。我正在使用PostgreSQL,并且不断遇到各种各样的问题。请帮忙。以下是我的任务型号:
from django_pg import models
from django.contrib.auth.models import User
# Create your models here.
OUTCOME_CHOICES = (
('U', 'Unsuccessful'),
('S', 'Successful'),
)
STATS_CHOICES = (
('1', 'Extremely Low'),
('2', 'Very Low'),
('3', 'Low'),
('4', 'Average'),
('5', 'Good'),
('6', 'Above Average'),
('7', 'High'),
('8', 'Very High'),
('9', 'Super Human'),
('10', 'Above and Beyond'),
)
class Hero(models.Model):
codename = models.CharField(max_length = 20)
def __str__(self):
return self.codename
class Team (models.Model):
name = models.CharField(max_length = 20)
address = models.CharField(max_length = 100)
description = models.TextField
leader = models.CharField(max_length = 20)
members = models.TextField
class Customer(models.Model):
first_name = models.CharField(max_length = 25)
surname = models.CharField(max_length = 30)
address = models.CharField(max_length = 100)
citizenship = models.CharField(max_length = 40)
class Mission(models.Model):
customer = models.ForeignKey('Customer')
description = models.TextField
location = models.CharField(max_length = 50)
difficulty = models.CharField(max_length = 20)
def __str__(self):
return self.description, self.location, self.difficulty
class Alias(models.Model):
hero = models.ForeignKey('Hero')
first_name = models.CharField(max_length = 25)
surname = models.CharField(max_length = 30)
former_codenames = models.TextField
occupation = models.CharField(max_length = 30)
address = models.CharField(max_length = 100)
citizenship = models.CharField(max_length = 30)
class HeroStats(models.Model):
hero = models.ForeignKey('Hero')
height = models.CharField(max_length = 10)
weight = models.CharField(max_length = 10)
powers = models.TextField
intelligence = models.CharField(max_length = 5, choices = STATS_CHOICES)
stamina = models.CharField(max_length = 5, choices = STATS_CHOICES)
strength = models.CharField(max_length = 5, choices = STATS_CHOICES)
class HeroStatus(models.Model):
hero = models.ForeignKey('Hero')
hero = models.IntegerField
mission = models.IntegerField
team = models.IntegerField
def __str__(self):
return "{0} is registered in team {1}, and is currenly on mission {3}".format(self.hero, self.team, self.mission)
class Report(models.Model):
mission = models.ForeignKey('Mission')
outcome = models.CharField(max_length = 15, choices = OUTCOME_CHOICES)
comments = models.TextField
def __str__(self):
return self.outcome
尝试过,但仍然存在错误。我在问题中解释了同样的情况。只是我正在使用django 1.8。 –
@SahanaPrabhakar这个问题已经过了一年多了,如果它不适合你,我建议你问一个新问题,并且包含足够的细节来重现问题。 – Alasdair