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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:40:10+00:00 2026-05-12T22:40:10+00:00

I have a django app with four models in it. I realize now that

  • 0

I have a django app with four models in it. I realize now that one of these models should be in a separate app. I do have south installed for migrations, but I don’t think this is something it can handle automatically. How can I migrate one of the models out of the old app into a new one?

Also, keep in mind that I’m going to need this to be a repeatable process, so that I can migrate the production system and such.

  • 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-12T22:40:10+00:00Added an answer on May 12, 2026 at 10:40 pm

    How to migrate using south.

    Lets say we got two apps: common and specific:

    myproject/
    |-- common
    |   |-- migrations
    |   |   |-- 0001_initial.py
    |   |   `-- 0002_create_cat.py
    |   `-- models.py
    `-- specific
        |-- migrations
        |   |-- 0001_initial.py
        |   `-- 0002_create_dog.py
        `-- models.py
    

    Now we want to move model common.models.cat to specific app (precisely to specific.models.cat).
    First make the changes in the source code and then run:

    $ python manage.py schemamigration specific create_cat --auto
     + Added model 'specific.cat'
    $ python manage.py schemamigration common drop_cat --auto
     - Deleted model 'common.cat'
    
    myproject/
    |-- common
    |   |-- migrations
    |   |   |-- 0001_initial.py
    |   |   |-- 0002_create_cat.py
    |   |   `-- 0003_drop_cat.py
    |   `-- models.py
    `-- specific
        |-- migrations
        |   |-- 0001_initial.py
        |   |-- 0002_create_dog.py
        |   `-- 0003_create_cat.py
        `-- models.py
    

    Now we need to edit both migration files:

    #0003_create_cat: replace existing forward and backward code
    #to use just one sentence:
    
    def forwards(self, orm):
        db.rename_table('common_cat', 'specific_cat') 
    
        if not db.dry_run:
            # For permissions to work properly after migrating
            orm['contenttypes.contenttype'].objects.filter(
                app_label='common',
                model='cat',
            ).update(app_label='specific')
    
    def backwards(self, orm):
        db.rename_table('specific_cat', 'common_cat')
    
        if not db.dry_run:
            # For permissions to work properly after migrating
            orm['contenttypes.contenttype'].objects.filter(
                app_label='specific',
                model='cat',
            ).update(app_label='common')
    

    #0003_drop_cat:replace existing forward and backward code
    #to use just one sentence; add dependency:
    
    depends_on = (
        ('specific', '0003_create_cat'),
    )
    def forwards(self, orm):
        pass
    def backwards(self, orm):
        pass
    

    Now both apps migrations are aware of the change and life sucks just a little less 🙂
    Setting this relationship between migrations is key of success.
    Now if you do:

    python manage.py migrate common
     > specific: 0003_create_cat
     > common: 0003_drop_cat
    

    will do both migration, and

    python manage.py migrate specific 0002_create_dog
     < common: 0003_drop_cat
     < specific: 0003_create_cat
    

    will migrate things down.

    Notice that for upgrading of schema I used common app and for downgrading, I used specific app. That’s because how the dependency here works.

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

Sidebar

Related Questions

I have written a Django app that makes use of Python threading to create
I'm using Google App Engine and Django templates. I have a table that I
I have configured my Django app to run under Apache+FastCGI on Linux (Ubuntu, if
I have a pretty standard django app, and am wondering how to set the
For my Django app I have Events, Ratings, and Users. Ratings are related to
Is it dangerous to have your admin interface in a Django app accessible by
Say I have a blogging app in Django. How can i re-order the posts
I'm writing a simple real-estate listing app in Django. Each property needs to have
As the title suggests, I'm using Google App Engine and Django. I have quite
Does Django have any template tags to generate common HTML markup? For example, I

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.