Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7912259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:33:19+00:00 2026-06-03T13:33:19+00:00

I’m in the process of configuring my Django app for multiple databases, and as

  • 0

I’m in the process of configuring my Django app for multiple databases, and as a stop-gap measure, I’m using the following configuration in my settings.py:

READ_DATABASE = {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'thedatabase',
    'USER': 'read_only',
    'PASSWORD': '',
    'OPTIONS': {
        'init_command': 'SET storage_engine=INNODB'
    }
}

WRITE_DATABASE = {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'thedatabase',
    'USER': 'root',
    'PASSWORD': '',
    'OPTIONS': {
        'init_command': 'SET storage_engine=INNODB'
    }
}

DATABASES = {'default': WRITE_DATABASE,
             'read': READ_DATABASE}

These point to the same database, in order to emulate a master-slave pair. The read_only user, as you might guess, only has read permissions.

My database router looks like this:

from django.conf import settings 

class MasterSlaveRouter(object):

    def db_for_read(self, model, **hints):
        return 'read' 

    def db_for_write(self, model, **hints):
        return 'default' 

    def allow_relation(self, db1, db2, **hints):
        return True

    def allow_syncdb(self, db, model):
        return db in ('default',)

When running syncdb, it now crashes immediately after setting up the superuser, with the error:

django.db.utils.IntegrityError: (1062, "Duplicate entry 'auth-permission' for key 'app_label'")

The offending SQL that’s failing to execute is:

INSERT INTO `django_content_type` (`name`, `app_label`, `model`) VALUES (permission, auth, permission)

This error only occurs when the second read database is sepcified in my settings.py, when only a default database is present, the syncdb command completes successfully.

Any suggestions what could be causing this?

Edit: Django version is 1.2.3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:33:20+00:00Added an answer on June 3, 2026 at 1:33 pm

    After a few hours of tinkering, I’ve deduced that the reason this was occurring is because some Django models (in this case django.contrib.contenttype.models.ContentType, but also django.contrib.site.models.Site) have their own inbuilt caching mechanism.

    Since I have set up two different connections to the same database, this was causing a problem since the contenttype cache for the read-only connection was not being invalidated by a write to a ContentType model on the write connection.

    The solution to this was to change my db_for_read method to something like this:

        def db_for_read(self, model, **hints):
            if model._meta.app_label in ('contenttypes', 'sites'):
                return 'write'
            else:
                return 'read' 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.