pythondatabasedjangomodels

Django 1.6: Clear data in one table


I've a table name UGC and would like to clear all the data inside that table. I don't want to reset the entire app which would delete all the data in all the other models as well. Is it possible to clear only one single model? I also have South configured with my app, if that would help.


Solution

  • You could use raw SQL :

     cursor.execute(“DROP TABLE UGC”)
    

    or you could just use the ORM directly inside a Django shell :

    UGCModel.objects.all().delete()
    

    That would erase the data (not the table, though), so you have to be careful :)

    Another way (for completeness and to make use of South) would be to comment out the model in your models declaration, migrate and then put it back again (assuming there are no models with a reference to it.)

    HTH