首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Django中的数据库问题:由于依赖关系无法重置

Django中的数据库问题:由于依赖关系无法重置
EN

Stack Overflow用户
提问于 2009-11-10 02:38:32
回答 5查看 6.3K关注 0票数 17

我正在尝试重置Django中的数据库,使用:

代码语言:javascript
复制
python manage.py reset app

但会得到以下错误:

代码语言:javascript
复制
Error: Error: app couldn't be reset. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset app'. That's the SQL this command wasn't able to run.
The full error: cannot drop table app_record because other objects depend on it
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

这是我的models.py文件的样子:

代码语言:javascript
复制
class Record(models.Model):
    name = models.CharField(max_length=50, db_index=True)
    year = models.IntegerField(blank=True, null=True)
    def __unicode__(self):
        return self.name

class Class(models.Model):
    record = models.ForeignKey(Record)
    def __unicode__(self):
        return self.id

我知道我需要使用DROP...SQL中的级联命令,用于删除和重新创建数据库(django-admin.py的输出)。

但是如何直接从models.py编辑该SQL呢?

更新

好了,我已经知道了如何手动删除表格(数据库是postgres),我在这里为有同样问题的人做了说明:

代码语言:javascript
复制
python manage.py dbshell 
# drop table app_record cascade; 
# \q 
python manage.py reset app 

我仍然想知道是否有人有更好的方法来做这件事:)

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1702906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档