south migration: “database backend does not accept 0 as a value for AutoField” (mysql)

后端 未结 4 670
心在旅途
心在旅途 2021-02-18 19:19

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



        
4条回答
  •  温柔的废话
    2021-02-18 19:52

    A long-long time ago there was a problem with Autofield.

    https://code.djangoproject.com/ticket/17653

    an interesting quotes:

    A:

    It seems you are trying to save 0 to a ForeignKey which points to an AutoField. But, this is illegal, as the AutoField will not accept that value and so the ForeignKey can not hold that value either.

    B:

    So this fix creates another problem when you need to be able to accept a value of 0 (or if you are working on a DB that already has a value of 0!) in an autofield. In my case, I need to accept an ID of zero so that my foreign key can point to zero so that a unique constraint can work properly.

    It looks like you have 0 in "user"."user_id".
    But again... Full StackTrace, please...

提交回复
热议问题