我使用的是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