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 8388207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:25:19+00:00 2026-06-09T18:25:19+00:00

The Django docs recommend copying a model instance thus: original.pk = None original.save() But

  • 0

The Django docs recommend copying a model instance thus:

original.pk = None
original.save()

But if you “use inheritance” — apparently meaning if the model’s class is a subclass of a subclass of models.Model — you need to do it slightly differently.

Specifically, the doc says:

Due to how inheritance works, you have to set both pk and id to None:

and gives an example analogous to this:

original.pk = None
original.id = None
original.save()

This seems kludgey. In any case, I’d like to understand what’s going on. Why does using inheritance require you to set the id field to None also? Don’t all Django models inherit from models.Model in any case?

(NOTE: I’m omitting the bit from the doc about copying m2m fields, which incidentally seems even more kludgey.)

  • 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-09T18:25:20+00:00Added an answer on June 9, 2026 at 6:25 pm

    It’s because MTI (Multiple Table Inheritance), the type you’re talking about here, stores the object across multiple tables. Take this example:

    class Animal(models.Model):
        ...
    
    class Dog(Animal):
        ...
    

    When you create a Dog, all the fields on Animal are saved into the table for Animal, and just the fields directly on Dog are saved to the table for Dog. When you lookup the Dog later, Django queries both tables and stitches them together.

    Both tables, however need primary keys, and Django uses AutoFields for that, which are simply positive integer fields. So Dog has an id and Animal has an id. The pk is filled with the id for the Animal part because this is the main piece, and Dog‘s id doesn’t matter. However, if you’re going to make a copy, you need to copy both pieces. Otherwise, the Animal part will of the copy will not get it’s own Dog part of the copy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use assignment_tag from django docs: https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/#howto-custom-template-tags-simple-tags Test project: mysite/ manage.py polls/
The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
To extend the User object with custom fields, the Django docs recommend using UserProfiles
According to this section in the Django docs I should use {% blocktrans %}
I have the code form django docs , but this will output an error.
Looking through the Django docs and trying to figure out the use of the
I'm trying to follow the code from the django docs: class Person(models.Model): name =
This must be in the Django docs somewhere but I can't seem to find
The Django docs only list examples for overriding save() and delete() . However, I'd

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.