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

  • SEARCH
  • Home
  • 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 6556885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:00:10+00:00 2026-05-25T13:00:10+00:00

In django, I want to copy data from identical tables in one db to

  • 0

In django, I want to copy data from identical tables in one db to those in another — from ‘db01’ to ‘default’. Schema are identical.

>>> a=Household.objects.filter(h_identifier='H122000-48').using('db01')
>>> a[0].pk
>>> u'451465ea-0137-11e0-879a-70f1a16e0f80'
>>> a[0].save(using='default')
>>> b=Household.objects.filter(h_identifier='H122000-48').using('default')
>>> b[0].pk
>>> u'7c2484fe-8641-11e0-b080-00188b4d6b0e'

it works but the primary key for the record inserted into ‘default’ is not the same as the one fetched from ‘db01’. To maintain integrity with other tables, the pk must not change. The django docs section selecting-a-database-for-save suggests that since instance ‘a’ already has a primary, the same primary key will be used when a new record is inserted to ‘default’. I cannot get it to do that.

Does anyone know if this can be done? thanks in advance!!

(This may seem like an odd setup, but the application runs independently on disconnected netbooks during the day, and data is merged into a master db during the night when all the netbooks are docked. I can do it fine in mysql but would like to use the django ORM if possible.)

  • 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-05-25T13:00:11+00:00Added an answer on May 25, 2026 at 1:00 pm

    I know this is from a while ago, but I had the same issue today – judging by the key you’re using, your id field is of type UUIDField from django_extensions?

    It’s slightly buggy, as the pre_save signal will always ensure the key is replaced regardless of whether there’s one already existing. Subclassing it and replacing the pre_save function fixes it.

    class FixedUUIDField(UUIDField):
    def pre_save(self, model_instance, add):
        value = super(UUIDField, self).pre_save(model_instance, add)
        if self.auto and add and not value:
            value = unicode(self.create_uuid())
            setattr(model_instance, self.attname, value)
        return value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to move the field honk and it's data from one model to
I have a large data set of Course objects in a Django application. courses
I want django-registration (version 0.8) to use my custom form rather than the default
Using sqlite3 and Django I want to change to PostgreSQL and keep all data
I want to combine an object and a QuerySet in Django. My objects are
I have a site running in django and want to make it available on
I'm currently building a website with Django and want to host user bio style
I want a Django model to have a date field in which the year,
In Django admin I want to override and implement my own form for a
Here in my django ModelAdmin I want to filter foreignkey choices based on current

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.