我正在使用 Python 3.4 和 Django 1.9.1,我正在尝试迁移我的新模型。首先,我在命令提示符下写道:python manage.py makemigrations missions 并且没有问题。但后来我输入:
python manage.py 迁移任务
但我不断收到关于内容类型的错误:
'创建新内容类型时出错。请确保在尝试单独迁移应用程序之前迁移内容类型'
我试过查看类似的 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 COLUMN name'
但是我该怎么做呢?到目前为止,我还没有想出如何在 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
最佳答案
'error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually'
如错误所述,您应该在迁移您的应用程序之前迁移内容类型应用程序。
python manage.py migrate contenttypes
python manage.py migrate missions
关于Python Django 1.9迁移错误 'error creating new content types...',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35180358/