如何从Django中删除模型? [英] How to remove models from django?

查看:53
本文介绍了如何从Django中删除模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django中,如何删除已同步到数据库中的模型?

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

例如,在Django教程页面中,该代码如下

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()

然后,我使用 python manage.py sql polls python manage.py sql polls 将表创建到数据库中.但是,如果我做错了什么并且不再想要该模型,该怎么办.删除它的语法是什么?

Then I used python manage.py sql polls and python manage.py sql polls 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?

推荐答案

没有语法.Django不会删除表格或列.您必须手动更改数据库或使用像South这样的迁移工具.

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.

如果您只是在玩教程,那么更简单的方法是删除sqlite数据库文件并再次运行同步.

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

这篇关于如何从Django中删除模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆