Carlton, we have the exact same issue you described.  It took a lot of 
searching to even find someone who has the same problem which led us to the 
conclusion that we just didn't understand how to perform migrations with DB 
Routers in play.  As you described, we have:

Database A - contains the schema for auth, sessions, content-type, models 
for app A
Database B - contains the models for app B

Migrations for app A function correctly.
Migrations for app B do not function correctly.

Our goal is the same as yours - to have models for app B (in Database B) 
store it's content-type in Database A, which is actually the point of 
having an "app" label in the content types table.  We follow the same 
suggestions and examples and yield the same error messages.

We are convinced the solution is some subtlety in the DB Router code that 
we missed and continue to investigate.  Did you ever find the solution to 
this?

Thanks
-Jim


On Tuesday, December 15, 2015 at 4:30:25 PM UTC-5, Carlton Gibson wrote:
>
> Hi, 
>
> Using multiple DBs, with most models in the "default" db but models for a 
> single app being stored in a second DB, I've more or less copied the example 
> from the docs 
> <https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#an-example> for 
> a custom database router. (My example is essentially identical to the 
> `AuthRouter` class given.)
>
> This works perfectly *except* when I run the migration on the second DB. 
>
> The app relations are all created but I then get an error creating the 
> ContentType...
>
> > RuntimeError: Error creating new content types. Please make sure 
> contenttypes is migrated before trying to migrate apps individually.
>
> This occurs because the relation "django_content_type" does not exist in 
> the second database — that's correct: I'm expecting content types to be 
> written only to the "default" db. 
>
> My question is why is this error occurring? 
>
> 1. As per the docs, in my router, I am returning "None if there is no 
> suggestion" for all the router methods — particularly `db_for_write`, which 
> seems relevant here. 
> 2. Looking at the source, the default router returns `DEFAULT_DB_ALIAS` if 
> all the custom routers return None. 
>
> So 3. I can't see the error. :-) — I'm expecting the content type to be 
> written to the default db. 
>
> I can work around the issue here — but I'd like to understand it. Can 
> anyone with experience of this explain what I've done wrong?
>
> Kind Regards,
>
> Carlton 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2b461815-8b7a-4507-b7a9-07e54bf6c497%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to