我正在尝试遵循 django 教程,但有自己的任务。
Models.py 文件看起来像
from django.db import models
class User(models.Model):
nickname = models.CharField(max_length=30)
password = models.CharField(max_length=30)
email = models.EmailField()
reg_date = models.DateField()
class Question(models.Model):
head = models.CharField(max_length=50)
content = models.TextField()
author = models.ForeignKey(User)
date = models.DateField()
class Answer(models.Model):
content = models.TextField()
question = models.ForeignKey(Question)
author = models.ForeignKey(User)
date = models.DateField()
validity = models.BooleanField()
我制作了“python manage.py shell”并写了如下内容:
>>> u1 = User(nickname='Alex', password='123', email='alex@mail.ru', reg_date='2013-01-07')
>>> u1.save()
>>> u2 = User(nickname='Kate', password='abcde', email='kitten@mail.ru', reg_date='2012-12-15')
>>> u2.save()
user_list 给了我
[<User: User object>, <User: User object>]
但后来我退出并在代码中做了一些更改。在此之后,我无法创建 u1.delete() 或 u2.delete(),因为它告诉 NameError: name 'u1' is not defined,但仍然向我显示那里的两个用户列表。我还可以创建新的 u1 和 u2 并删除它们。我现在如何向那些以前的用户申请清除数据库?