1
votes

I am using Python 3.4 and Django 1.9.1 and I am trying to migrate my new model. First I write: python manage.py makemigrations missions in the command prompt and that worked without issue. But then I input:

python manage.py migrate missions

But I keep getting this error about the contenttypes:

'error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually'

I've tried looking around at similar stackoverflow question but nothing has been helpful. How do I get this error to stop? One such solution at Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually stated:

By manually removing the column name from 'django_content_type' table. Eg.

'ALTER TABLE django_content_type DROP COLUMN name'

But how do I do that? So far I haven't figured out how to use pure SQL statements like this in Django. I am using the PostgreSQL and I keep getting into all sorts of problems. Please help. Below is my missions model:

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
3

3 Answers

1
votes

'error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually'

As the error says, you should migrate the contenttypes app before you migrate your app.

python manage.py migrate contenttypes
python manage.py migrate missions
0
votes

run python manage.py makemigrations && python manage.py migrate.

If you give a specific app label (such as "missions"), you will only run migrations for that app. You can't migrate your own apps before the tables for the django core apps have been created.

-1
votes

I solved my problem by deleting all my migration files and dropping my database (I'm currently using sql lite. I just delete the DB). After that I simply ran the makemigration and migrate command.

I made the mistake of deleting a migration, made some changes and migrated again. This cause problem because my DB table were no longer in sync with my migration files.