1
我想跟着Django教程,但與我自己的任務。NameError:名稱'u1'未定義
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()
我做了 「蟒蛇manage.py殼」,寫了類似:
>>> u1 = User(nickname='Alex', password='123', email='[email protected]', reg_date='2013-01-07')
>>> u1.save()
>>> u2 = User(nickname='Kate', password='abcde', email='[email protected]', reg_date='2012-12-15')
>>> u2.save()
USER_LIST給我
[<User: User object>, <User: User object>]
但隨後我做了退出,並在代碼中做了一些更改。在此之後,我無法制作u1.delete()或u2.delete(),因爲它告訴NameError:名稱'u1'未定義,但仍顯示兩個用戶列表。我也可以創建新的u1和u2並刪除它們。我如何才能向那些以前的用戶申請清除數據庫?
謝謝!有效 – shutupandskate 2013-03-21 08:48:33