#13668: ManyToManyField passes ModelBase to router.db_for_write
-------------------------------------+--------------------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
-------------------------------------+--------------------------------------
When using a ManyToMany field without the through parameter, the incorrect
model type is passed into the router functions.
Consider the following example:
Models:
{{{
from django.db import models
class A(models.Model):
asdf = models.CharField(max_length=10)
class B(models.Model):
b = models.CharField(max_length=10)
asdfs = models.ManyToManyField('A')
}}}
Router:
{{{
class MyRouter(object):
def db_for_write(self, model, **hints):
if model._meta.app_label == 'model_app_label':
return 'not_default'
def db_for_read(self, model, **hints):
if model._meta.app_label == 'model_app_label'
return 'not_default'
def allow_relation(self, obj1, obj2, **hints):
return obj1._state.db == obj2._state.db
def allow_syncdb(self, db, model):
if db == 'not_default' and model._meta.app_label == 'model_app_label':
return True
if db == 'default' and model._meta.app_label == 'model_app_label':
return False
return None
}}}
Running the following bit of code:
{{{
aa = A.objects.create(asdf='1')
bb = B.objects.create(b='asdf')
bb.asdfs.add(aa)
}}}
I get an error about how the intermediary table `model_app_label_b_asdfs`
on the default database does not exist
--
Ticket URL: <http://code.djangoproject.com/ticket/13668>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.