社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

django1.9的用户认证auth 关于自定义扩展User报错,求解答

天真莫离 • 7 年前 • 1806 次点击  

请教个问题,我在使用django1.9(python2.7)的用户认证auth时,想扩展User,在使用继承AbstractUse,在migrate操作时报错:

---报错内容start---
>>>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, contenttypes, sql, auth, sessions
Running migrations:
  Rendering model states... DONE
  Applying admin.0001_initial...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Python27\lib\site-packages\django\db\migrations\migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Python27\lib\site-packages\django\db\migrations\operations\models.py", line 59, in database_forwards
    schema_editor.create_model(model)
  File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 235, in create_model
    definition, extra_params = self.column_sql(model, field)
  File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 134, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 962, in db_parameters
    return {"type": self.db_type(connection), "check": []}
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 953, in db_type
    rel_field = self.target_field
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 856, in target_field
    return self.foreign_related_fields[0]
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 591, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 578, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 563, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'sql.User' cannot be resolved

-------报错内容end-----

#sql.models.py文件内容,sql是app的名字
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):

    qq = models.CharField(max_length=16, blank=True, null=True, verbose_name=u'QQ')


#settings.py文件添加内容

AUTH_USER_MODEL = 'sql.User'
最后一次修改于 (2017-08-10 20:03)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/3009
 
1806 次点击  
文章 [ 1 ]  |  最新文章 7 年前