返回信息流用的是django1.8版本
myapp/models.py:
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question,related_name='Choice_set')
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __unicode__(self):
return self.choice_text
tests.py:
class QuestionMethodTests(TestCase):
def test_was_published_recently_with_future_question(self):
time = timezone.now()+datetime.timedelta(days=30)
future_question=Question(pub_date=time)
self.assertEqual(future_question.was_published_recently(),False)
运行test时报错:The database backend does not accept 0 as a value for AutoField.
有人遇到过这样的问题么?试了一些网上的解决方案还是不行啊。。。
这是一条镜像帖。来源:北邮人论坛 / python / #13286同步于 2016/4/12
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
照着django documentation上的例子出现的问题
upupup123
2016/4/12镜像同步9 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
【 在 napoleonwxu 的大作中提到: 】
: 数据库设置正确么?
数据库设置应该是没有错,因为我在终端可以对其进行增删查改操作 不过每次会有warming:The database backend does not accept 0 as a value for AutoField. 当我运行这个tests的时候是直接报错了。。。
没遇到过唉,autoField应该是默认添加的id字段吧,自动从1开始自增的那个。不知道为什么会有0这个值,我也觉得是不是数据库的auotoincrement是不是有什么问题。我瞎扯的,仅供参考
【 在 Agosits 的大作中提到: 】
: 没遇到过唉,autoField应该是默认添加的id字段吧,自动从1开始自增的那个。不知道为什么会有0这个值,我也觉得是不是数据库的auotoincrement是不是有什么问题。我瞎扯的,仅供参考
好的~~多谢多谢,我再看看到底怎么回事。。。
MySQL 不接受0作为 auto increment 的值,不过不知道为什么 Autofield 会有0值。
这里有相关讨论 http://stackoverflow.com/questions/20328905/south-migration-database-backend-does-not-accept-0-as-a-value-for-autofield
【 在 upupup123 的大作中提到: 】
: 对呀 用的mysql 和这个有什么关系么?
: 是不是用了 MySQL ?