﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2864	Creating a ManyToManyField - order of classes	merric@…	Adrian Holovaty	"If you create a ManyToMany field in a class BEFORE the class being referenced and then use ""manage.py syncdb"" you get an error.  The samples below show exactly the same classes.  However, the first example works and the second does not.  The order of the classes is important. This is either a bug or if it isn't there should be something in the documentation.  I wasted a couple of hours trying to figure out what was wrong.


THIS WORKS
--------------------
from django.db import models
import datetime

# Create your models here.

class Promoter(models.Model):
    promoter_name = models.CharField(maxlength=200)
    class Admin:
        pass

class Category(models.Model):
    category_name = models.CharField(maxlength=400)
    class Admin:
        pass


class Promotion(models.Model):
    promoter_id = models.ForeignKey(Promoter)
    categories = models.ManyToManyField(Category)
    promo_headline=models.CharField(maxlength=300)
    class Admin:
        pass

THIS DOES NOT WORK (Classes in different order)
------------------------
from django.db import models
import datetime

# Create your models here.

class Promoter(models.Model):
    promoter_name = models.CharField(maxlength=200)
    class Admin:
        pass

class Promotion(models.Model):
    promoter_id = models.ForeignKey(Promoter)
    categories = models.ManyToManyField(Category)
    promo_headline=models.CharField(maxlength=300)
    class Admin:
        pass

class Category(models.Model):
    category_name = models.CharField(maxlength=400)
    class Admin:
        pass
"	defect	closed	Database layer (models, ORM)	0.95	major	invalid			Unreviewed	0	0	0	0	0	0
