How to remove models from django?

0

Issue

In Django how do you remove models that you have synced into the database?

For example in Django tutorial page had this following code

from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

Then I used python manage.py sql polls and python manage.py sql choice to create the tables into the database. But what if I did something wrong and don’t want that model any more. What’s the syntax to remove it?

Solution

There is no syntax. Django doesn’t removes tables or columns. You have to manually change your database or use a migration tool like South.

If you justing playing around with tutorial the easier way is to delete your sqlite database file and run a sync again.

Answered By – Cesar Canassa

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More