django用户的默认外键值 [英] django default foreign key value for users

查看:238
本文介绍了django用户的默认外键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通读

I've had a read through http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ but still am having problems migrating my new db schema with a ForeignKey for a user in a list of products

我的代码的简化版本是:

a simplified version of my code is:

from django.contrib.auth.models import User
# other imports

class Product(models.Model):

 author = models.ForeignKey(User)
 # other product fields..

但是当我尝试迁移到South时,这可能是问题所在,因为我的用户数据库没有由South处理(请原谅我的新手),我收到错误消息,需要设置默认值:

but when I try to migrate to South, and this may be the problem, as my user database is not handled by South (??forgive my newbieness) i'm getting errors that a default value needs to be set:

_mysql_exceptions.OperationalError: (1067, "Invalid default value for 'author_id'")

任何人都可以解释我在做什么错吗?理想情况下,我不需要用户的默认值,或者至少不想要null,false或0(但这似乎不起作用).

Can anyone explain what i'm doing wrong?? Ideally I wouldn't want a default value for the user, or at least null, false or 0 (but that doesn't seem to work)..

非常感谢

adam

推荐答案

最终采取了简单的方法,完全重置了产品表,并从头开始进行了迁移.不确定我是否学到了什么(除了如何重置应用程序以外!)!

Ended up taking the easy route and totally resetting the product table, and migrating from scratch which worked. Not sure i've learnt anything (other than how to reset an app)!

这篇关于django用户的默认外键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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