小编Nim*_*ima的帖子

与django 1.7的Django注册兼容性问题

我一直在使用[django-registration](https://bitbucket.org/ubernostrum/django-registration),现在我已经开始使用django 1.7b1了,这是我收到下面复制的错误的错误.它是从django-registration中提出的models.py:

try:
    from django.contrib.auth import get_user_model
    User = get_user_model()
except ImportError:
    from django.contrib.auth.models import User
Run Code Online (Sandbox Code Playgroud)

它似乎正在被提出,因为get_user_model()在app注册表准备好之前被调用.我不确定这是否是兼容性问题,如果是,是否有一个简单的解决方法?如果没有,你能帮我辨别我做错了吗?

RuntimeError: App registry isn't ready yet.
File "/Users/nima/pe-dev/manage.py", line 9, in <module>
  execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/core/management/__init__.py", line 427, in execute_from_command_line
  utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/core/management/__init__.py", line 391, in execute
  django.setup()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/__init__.py", line 21, in setup
  apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/registry.py", line 106, in populate
  app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/config.py", line 190, in import_models
  self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name) …
Run Code Online (Sandbox Code Playgroud)

django django-registration django-1.7

11
推荐指数
1
解决办法
5937
查看次数

使用迁移为Django中的模型字段添加索引

我正在尝试使用Field.db_index具有迁移的应用程序在模型字段上添加索引.看看Django的文档我需要做的就是设置db_index=True:

class Person(models.Model):
    first_name = models.CharField()
    last_name = models.CharField(db_index=True)
Run Code Online (Sandbox Code Playgroud)

然后我首先尝试了新的Django迁移:

./manage.py makemigrations app-name
Run Code Online (Sandbox Code Playgroud)

但是迁移似乎没有注意到更改,也没有添加用于创建索引的sql命令.所以我试着django-admin.py按照这里的解释:

django-admin.py sqlindexes app-name
Run Code Online (Sandbox Code Playgroud)

但是,这也不会打印sql命令,它会退出并出现以下错误:

CommandError: App 'app-name' has migrations. Only the sqlmigrate and sqlflush commands can be used when an app has migrations.
Run Code Online (Sandbox Code Playgroud)

django django-models django-admin django-migrations django-2.1

10
推荐指数
3
解决办法
4980
查看次数