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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:44:44+00:00 2026-05-27T23:44:44+00:00

I wrote python script for dropping tables in all Django apps. (using settings.INSTALLED_APP) https://gist.github.com/1520683

  • 0

I wrote python script for dropping tables in all Django apps. (using settings.INSTALLED_APP)

https://gist.github.com/1520683

My django project creates 41 tables after running manage.py syncdb, but my script says only 40 tables will be dropped. So, I examined the result of sqlall and result of sqlclear. And I revealed sqlclear omits one table that stores ManyToManyField relationship.

I knew that drop database is much simpler than the above script. But I confused why django admin or manage script omit some tables while running sql commands.


Below model creates common_userbook_purchasedBooks table while running syncdb, but not in sqlclear command.

class UserBook(models.Model):                       
    user = models.OneToOneField(User)
    purchasedBooks = models.ManyToManyField(Book)

Added) So, I’m using an alternative approach for this.
https://gist.github.com/1520810

  • 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-27T23:44:45+00:00Added an answer on May 27, 2026 at 11:44 pm

    lqez, I gues this issue related to you local environment, because for Django 1.3.1, Python 2.7.2

    for models

    from django.contrib.auth.models import User
    from django.db import models
    
    class Book(models.Model):
        name = models.CharField(max_length=10)
    
    class UserBook(models.Model):
        user = models.OneToOneField(User)
        purchasedBooks = models.ManyToManyField(Book)
    

    when I run (.env)testme$ ./manage.py sqlclear testapp output looks like

    sqlite3

    BEGIN;
    DROP TABLE "testapp_userbook";
    DROP TABLE "testapp_userbook_purchasedBooks";
    DROP TABLE "testapp_book";
    COMMIT;
    

    postgresql_psycopg2

    BEGIN;
    ALTER TABLE "testapp_userbook_purchasedBooks" DROP CONSTRAINT "userbook_id_refs_id_8bda4b0";
    DROP TABLE "testapp_userbook";
    DROP TABLE "testapp_userbook_purchasedBooks";
    DROP TABLE "testapp_book";
    COMMIT;
    

    mysql

    BEGIN;
    ALTER TABLE `testapp_userbook_purchasedBooks` DROP FOREIGN KEY `userbook_id_refs_id_8bda4b0`;
    DROP TABLE `testapp_userbook`;
    DROP TABLE `testapp_userbook_purchasedBooks`;
    DROP TABLE `testapp_book`;
    COMMIT;
    

    Also your script can be a little bit improved using introspection:

    from django.db import connection
    cursor = connection.cursor()
    connection.introspection.get_table_list(cursor)
    
    [u'auth_group', u'auth_group_permissions', u'auth_message', u'auth_permission', u'auth_user', u'auth_user_groups', u'auth_user_user_permissions', u'django_content_type', u'django_session', u'django_site', u'testapp_book', u'testapp_userbook', u'testapp_userbook_purchasedBooks']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script I recently wrote that I call using the command
I wrote a simple python script using the SocketServer, it works well on Windows,
I wrote a python script which I am using to download a large number
I just wrote a small python script that gets me all the groups on
I am writing python script to login to ssh server using paramiko. I wrote
I wrote a Python script that does some task to generate, and then keep
I wrote a Python GUI script with Tkinter, and now I want to convert
I wrote the following script, which generates a SyntaxError : #!/usr/bin/python print Enter the
I'm just beginning to learn python. I wrote an example script to test OOP
I wrote a python script that depends on a certain NFS share to be

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.