向南迁移:“数据库后端不接受0作为AutoField的值”。 (mysql) [英] south migration: "database backend does not accept 0 as a value for AutoField" (mysql)

查看:167
本文介绍了向南迁移:“数据库后端不接受0作为AutoField的值”。 (mysql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是django的新手,正在尝试为外派人员和记者找回外键。
但是当我尝试对South应用更改时,出现错误

I'm new to django and trying to have a Foreign key back to users for an assignee and reporter. But when i'm trying to apply the change with South i get the error

ValueError: The database backend does not accept 0 as a value for AutoField.

我的模型代码:

class Ticket(models.Model):
    title = models.CharField(max_length=80)
    text = models.TextField(blank=True)
    prioritys = models.ForeignKey(Prioritys)
    ticket_created = models.DateTimeField(auto_now_add=True)
    ticket_updated = models.DateTimeField(auto_now=True)
    assignee = models.ForeignKey(User, null=True, related_name='assignee')
    reporter = models.ForeignKey(User, null=True, related_name='reporter')

    def escaped_text(self):
        return markdown.markdown(self.text)

    def __unicode__(self):
        return self.text


推荐答案

如果在运行 manage.py migration (或 manage.py syncdb)时发生这种情况(在旧版本中),原因可能是您试图向使用AutoField作为其主键并使用0作为默认值的模型添加外键t值。 编辑迁移文件,并在AddField操作中删除参数 default = 0 它在Django 1.10中对我有用。

If this happens when you run manage.py migrate (or manage.py syncdb in old versions), the reason maybe is that you have tried to add a foreign key to a model which uses AutoField as its primary key, and use 0 as the default value. Edit the migration file and remove the argument default=0 in AddField operations. It works for me in Django 1.10.

这篇关于向南迁移:“数据库后端不接受0作为AutoField的值”。 (mysql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆