我正在尝试重置Django中的数据库,使用:
python manage.py reset app
但会得到以下错误:
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文件的样子:
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),我在这里为有同样问题的人做了说明:
python manage.py dbshell
# drop table app_record cascade;
# \q
python manage.py reset app
我仍然想知道是否有人有更好的方法来做这件事:)
https://stackoverflow.com/questions/1702906
复制相似问题