8
Scenario
I have a basic Django app in which users (django's authentication built in model) and reports have a many-to-many relationship.
The Problem
Django does not create a corresponding table to handle this relationship. My application is called reports. There is an error in the admin system upon trying to create a report and assign users to it. It tries to query the table reports_report_users and it fails as it does not exist.
models.py code
from django.db import models
from django.contrib.auth.models import User
class Report(models.Model):
name = models.CharField(max_length=30, blank=False)
users = models.ManyToManyField(User, related_name='reports')
def __unicode__(self):
return self.name
Attempted Solutions
- Used this link as a reference: https://docs.djangoproject.com/en/1.4/topics/db/examples/many_to_many/
- Ran
manage.py syncdbabout 300 times - ok, only once, but there were no errors and upon inspecting the SQLite db there were no additional tables created :(