2013-03-28 2 views
1

내 전자 상거래 사이트에는 3 가지 모델을 정의하는 models.py가 있습니다. 원래는 ProductCategory 두 개만 정의 했었지만 제품에 특정 키워드를 붙일 수 있어야한다는 것을 알았습니다. 그래서이 모델을 추가했습니다. syncdb을 시도하고 새로운 tag 테이블을 만들었지 만 products_tags '통과'테이블을 만들 때 문제가 발생했습니다.Django ManyToManyField가 "through"테이블을 만들지 못함

class Category(models.Model): 
    **a bunch of variables** 

    class Meta: 
     db_table = 'categories' 
     ordering = ['name'] 
     verbose_name_plural = 'Categories' 

    def __unicode__(self): 
     return self.name 

    @models.permalink 
    def get_absolute_url(self): 
     return ('catalog_category',(), { 'category_slug': self.slug }) 

class Tag(models.Model): 
    **a bunch of variables** 

    class Meta: 
     db_table = 'tags' 
     ordering = ['name'] 
     verbose_name_plural = 'Tags' 

    def __unicode__(self): 
     return self.name 

class Product(models.Model): 
    **a bunch of variables** 
    categories = models.ManyToManyField(Category, related_name='cat+') 
    tags = models.ManyToManyField(Tag, related_name='tag+') 

    class Meta: 
     db_table = 'products' 
     ordering = ['-created_at'] 

    def __unicode__(self): 
     return self.name 

는 모든 것이 아름답게 유효성을 확인, 나는 python manage.py syncdb을 실행할 때 모든 테이블은 당신이 기대 적절한 행과 유형 및 다른 모든 것들로 만들어집니다. 단, Product 클래스에 설정된 ManyToMany 관계로 인해 만들려는 products_tags 테이블을 만들지 않습니다. products_categories '통과'테이블을 만들었지 만 products_tags 테이블을 만들지 못하는 이유는 무엇입니까?

+1

태그를 추가 할 때 ManyToMany 필드와 db를 동기화 할 때 제품 테이블이 이미 존재합니까? 그렇다면 django는 syncdb의 필드 레벨 변경을 식별 할 수 없습니다. DB를 지우고 다시 동기화하거나 [django south] (http://south.aeracode.org/)를 사용하십시오 –

+0

그 제한을 알지 못했습니다. 나는 장고 남쪽을 살펴볼 것이다. 감사합니다 Aamir! – fildred13

답변

1

Aamir은 자신의 의견에서 syncdb에는 마이그레이션 기능이 없으므로 new through 테이블을 만들 수 없었습니다. 내가 장고 남쪽을 설치하고 지금 테이블을 업데이 트하는 것은 예상대로 진행되고있다.

관련 문제