添加用户配置文件(此处称为用户信息)后,我的 models.py 文件不会同步数据库。我明白了:TypeError: __init__() takes at least 2 arguments (1 given)
上面提到的所有错误都提到了 models.py 文件或与之相关的一些文件。
模型.py 文件:
def create_user_info(sender, instance, created, **kwargs):
if created:
UserInfo.objects.create(user=instance)
post_save.connect(create_user_info, sender=User)
class Book(models.Model):
title = models.CharField(max_length=50)
author = models.CharField(max_length=50)
def __unicode__(self):
return self.title
class UserInfo(models.Model):
user = models.OneToOneField(User)
pen_name = models.CharField(max_length=30)
activated = models.BooleanField()
def __unicode__(self):
return self.email + '-' + self.pen_name
在 settings.py 中进行身份验证:
AUTH_PROFILE_MODULE = 'Knights.UserInfo'
追溯:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/base.py", line 231, in execute
self.validate()
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/Mike/Desktop/Main/Django-Development/BBN/Knights/models.py", line 53, in <module>
class Alert(models.Model):
File "/Users/Mike/Desktop/Main/Django-Development/BBN/Knights/models.py", line 55, in Alert
for_user = models.ForeignKey()