Tuesday, December 15, 2015

"Error creating new content types" with multiple DB router

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 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+unsubscribe@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/013ef727-b914-4986-b037-f8fae258af86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment