I have a problem when trying to run syncdb. My models:
class TeachSubject(models.Model):
teacher = models.ForeignKey(User)
taught_class = models.ForeignKey(SchoolClass)
subject = models.ForeignKey(Subject)
year = models.IntegerField(default=datetime.date.today().year)
semester = models.IntegerField()
#class Meta:
#db_table = 'subject_teachers'
another file:
from customUsers.models import TeachSubject
class SubjectPeriod(models.Model):
days = ((1, 'Mon'),
(2, 'Tues'),
(3, 'Wed'),
(4,'Thurs'),
(5,'Friday'))
tsc = models.ForeignKey(TeachSubject)
day = models.IntegerField(choices = days)
period = models.IntegerField()
class Meta:
db_table = 'subject_period'
unique_together = ('day', 'period', 'tsc')
Tried running syncdb, the table subject_period is created alright. The thing is, after checking the database itself, strangely no foreign key constraint is created for the line tsc = models.ForeignKey(TeachSubject).
Anyone can shed some light? Using django 1.2.4 (ps. I spent some time checking before posting here. So I beg your forgiveness if it was a careless mistake)
EDIT:
ok I deleted the tables and retried creating the tables using south instead. Works fine now, but it would be still good to know what went wrong with the former method.
I assume your two models are from different apps.
The docs says:
To refer to models defined in another application, you can explicitly specify a model with the full application label. For example, if the Manufacturer model above is defined in another application called production, you’d need to use:
so your foreignkeyfield will look like:
This also means you don’t have to import the models from the other application (also solving problems of circular imports.
It seems strange that you dont get an error – just nothing at all – but try that, it might just work.