2014-06-05 1 views
0

두 가지 다른 응용 프로그램에서 3 가지 모델 간의 관계를 사용하려고합니다. 여기서 볼 수 있듯이 내가 설정에 대한 모든 프로젝트에서 응용 프로그램 및 django.contrib.sites를 설치 한유효성 검사 오류 Django는 여러 응용 프로그램과의 관계를 모델링합니다.

CommandError: One or more models did not validate: 
tournaments.tournament: 'city' has a relation with model City, which has either not been installed or is abstract. 
tournaments.tournament: 'sport' has a relation with model Sport, which has either not been installed or is abstract. 

: 나는 장고 모델의 유효성을 검사 할 때 다음과 같은 오류가 발생했습니다.

INSTALLED_APPS = (
    'django.contrib.sites', 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'location', 
    'sport', 
    'team', 
    'tournament', 
) 

목록의 앱 순서도 변경하려고했습니다.

이것은 위치 응용 프로그램 모델입니다.

from django.db import models 


class Country(models.Model): 
    name = models.CharField('Country', max_length=200, unique=True) 
    abbr = models.CharField('Abbreviation', max_length=6, unique=True) 

    class Meta: 
     ordering = ('name',) 
     app_label = 'location' 
     verbose_name_plural = 'countries' 

    def __unicode__(self): 
     return self.name 


class State(models.Model): 
    country = models.ForeignKey('Country', verbose_name=u'country') 
    name = models.CharField('State', max_length=200, unique=True) 
    abbr = models.CharField('Abbreviation', max_length=6, unique=True) 

    class Meta: 
     ordering = ('country', 'name') 
     unique_together = ('name', 'country') 
     app_label = 'location' 

    def __unicode__(self): 
     return self.name 


class City(models.Model): 
    state = models.ForeignKey('State', verbose_name=u'state') 
    name = models.CharField('City', max_length=200, unique=True) 
    abbr = models.CharField('Abbreviation', max_length=6, unique=True) 

    class Meta: 
     ordering = ('state', 'name') 
     unique_together = ('name', 'state') 
     app_label = 'location' 
     verbose_name_plural = 'cities' 

    def __unicode__(self): 
     return self.name 

뿐만 아니라 스포츠 응용 프로그램의 모델

from django.db import models 


class Sport(models.Model): 

    name = models.CharField('Sport', max_length=200, unique=True) 
    abbr = models.CharField('Abbreviation', max_length=6, unique=True) 

    class Meta: 
     ordering = ('name',) 
     app_label = 'sport' 
     db_table = 'sports' 

    def __unicode__(self): 
     return self.name 

내가 여기 밖으로 많은 운영 체제 게시물을 읽은

from django.db import models 
from location.models import City 
from sport.models import Sport 


class Tournament(models.Model): 

    territory = (
     (1, u'International'), 
     (2, u'National'), 
     (3, u'Regional'), 
    ) 

    name = models.CharField('Tournament', max_length=200, unique=True) 
    abbr = models.CharField('Abbreviation', max_length=6, unique=True) 
    city = models.ForeignKey('City', verbose_name=u'city') 
    sport = models.ForeignKey('Sport', verbose_name=u'sport') 
    regional = models.PositiveIntegerField(u'Status', default=1, choices=territory) 
    start = models.DateTimeField('Start Date') 
    end = models.DateField('End Date') 

    def __unicode__(self): 
     return self.name 

    class Meta: 
     ordering = ('name',) 
     unique_together = ('name', 'city', 'regional') 
     app_label = 'tournament' 

마지막 대회 응용 프로그램의 모델이며, 장고의 프로젝트 문서,하지만 잘못 된 것을 찾을 수 없습니다.

답변

0

먼저 모든 앱에서 python manage.py syncdb을 (를) 수행했는지 또는 사우스 마이 그 레이션을 실행 했습니까?

는이 라인

이에
city = models.ForeignKey('City', verbose_name=u'city') 
sport = models.ForeignKey('Sport', verbose_name=u'sport') 

을 변경 시도?

city = models.ForeignKey('location.City', verbose_name=u'city') 
sport = models.ForeignKey('location.Sport', verbose_name=u'sport') 
+0

감사합니다. 완벽하게 작동했습니다. 어쨌든, 나는 syncdb를 실행하려했지만 실패했다. 남쪽도 시도하지 않았다. –