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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:19:27+00:00 2026-06-13T11:19:27+00:00

I have a Django app, the database for which is under active manual development

  • 0

I have a Django app, the database for which is under active manual development (it’s a language-learning app, so it stores vocabulary, grammatical concepts, etc). I’d prefer to do that development in my local django/postgres environment.

However, I don’t want to be constantly wiping out the User table from the live version!

I’m very new to Postgres, so please don’t assume I know what I’m doing here – would some kind of schema be the right approach here?

  • 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-13T11:19:28+00:00Added an answer on June 13, 2026 at 11:19 am

    To just backup the one table, use COPY from inside the database:

    COPY user_tbl TO '/path/to/file';
    

    or pg_dump from the shell:

    pg_dump -t user_tbl mydb > user_tbl.sql
    

    Then drop the database, restore your new version, empty user_tbl and use COPY FROM to restore the one table:

    COPY user_tbl FROM  '/path/to/file';
    

    or restore the backup with the one table from the shell with psql:

    psql -f user_tbl.sql mydb
    

    Identify depending tables

    Quick and dirty

    There is no such thing as “COPY … CASCADE”. The simplest method to identify depending tables would be to start a transaction, call TRUNCATE tbl CASCADE and record the notices you get:

    BEGIN;
    TRUNCATE user_tbl CASCADE;
    
    NOTICE:  truncate cascades to table "tbl1"
    NOTICE:  truncate cascades to table "tbl2"
    NOTICE:  truncate cascades to table "tbl3"
    

    Then roll back the transaction – so nothing actually changes:

    ROLLBACK;
    

    Careful with that. If you COMMIT the truncate goes through.

    Slow and sure

    Well, not actually “slow”, but the code is a lot more complex. This doesn’t take an exclusive lock on the involved tables, though, so it’s a lot cleaner and safer:

    WITH RECURSIVE x AS (
        SELECT conrelid::regclass
        FROM   pg_constraint
        WHERE  confrelid = 'user_tbl'::regclass
    
        UNION
        SELECT p.conrelid::regclass
        FROM   x
        JOIN   pg_constraint p ON p.confrelid = x.conrelid
        )
    SELECT conrelid::text AS tbl
    FROM   x;
    

    Returns:

    tbl
    ------
    tbl1
    tbl2
    tbl3
    

    I use a recursive CTE (requires PostgreSQL 8.4 or later) on the catalog table pg_constraint, because each table can have dependencies in turn.
    Use UNION, not UNION ALL to avoid multiple evaluation of tables that might be linked with multiple foreign keys directly or indirectly.

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

Sidebar

Related Questions

I have a django app which is used for managing registrations to a survey.
I have a Django app which uses LDAP as the authentication backend. I'm not
I have some django apps which are versioned by app name. appv1 appv2 The
I'm creating a Django app in which I have a table which has 'items',
We have this open source app we built with Django http://map.ninux.org/ which is used
I want to develop an Android app, which stores results in a database. This
I have a django app which basically is just a photo album. Right now
I have a Django application which I decided to port to Google App Engine.
I have a Django app that gets it's data completely from an external source
I have a Django app written in Python 2.5 and I plan to upgrade

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.