- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我收到错误
ImproperlyConfigured at /admin/
AUTH_USER_MODEL refers to model 'ledger.User' that has not been installed
我只在我的生产服务器上获取它。当我通过本地主机运行时则不然。首先,只有当我提出某个要求时。然后我认为我的数据库一定不同步,所以我删除了所有表,然后运行manage.pysyncdb。现在,它似乎已经传播,甚至到管理员那里都会抛出错误。
我以前从未见过此错误,无法弄清楚这是什么原因。我已经在settings.py中定义了AUTH_USER_MODEL:
...
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ledger',
'extension',
'plugin',
'social.apps.django_app.default',
)
AUTH_USER_MODEL = 'ledger.User'
...
模型.py:
...
class User(AbstractUser):
def __unicode__(self):
return self.username
balance = models.IntegerField(default=0)
total_pledged = models.IntegerField(default=0)
last_pledged = models.ForeignKey('Transaction', related_name='pledger', blank=True, null=True)
extension_key = models.CharField(max_length=100, null=True, blank=True)
plugin_key = models.CharField(max_length=100, null=True, blank=True)
ghosted = models.BooleanField(default=False)
def save(self, *args, **kwargs):
print('saving')
try:
self.company.save()
except:
print('no company')
super(User, self).save(*args, **kwargs)
...
最佳答案
我遇到了这个问题,通过正确理解 Django 文件的结构解决了这个问题。
教程中的说明通常各不相同且令人困惑。
你需要明白,当你安装Django时,有两个关键步骤:
1:创建项目2:创建app(应用程序)
让我们按照 Django 官方教程来说明问题:
https://docs.djangoproject.com/en/3.1/intro/tutorial01/
第 1 步:创建一个新项目:
django-admin startproject mysite
您现在会发现有一个名为“mysite”的目录
**第 2 步:**该教程说:要创建您的应用,请确保您位于与 manage.py 相同的目录中,然后输入以下命令:这是刚刚创建的目录,因此请转到:
cd mysite
如果你ls那么你会在这个目录中找到:名为 manage.py 的文件令人困惑的是,另一个名为 mysite
的目录第 3 步:现在教程说创建你的 Django 应用程序:
python manage.py startapp polls
现在 ls 显示这些文件:管理.py
我的网站
民意调查
Consufion 可能现在已经生效,因为所有这些文件都位于 mysite 目录下。
第 4 步:如果您想使用自定义用户模型,那么官方建议是在项目开始时在进行任何迁移之前执行此操作。
好的,编辑 mysite/settings.py 并添加以下行:
AUTH_USER_MODEL = 'polls.User'
并编辑民意调查/模型并添加:
from django.db import models
# Create your models here.
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
** 步骤 5:**那么现在应该可以进行第一次迁移了,对吧?
python manage.py makemigrations
但是啪!
Traceback (most recent call last):
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/apps/registry.py", line 156, in get_app_config
return self.app_configs[app_label]
KeyError: 'polls'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 157, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/apps/registry.py", line 206, in get_model
app_config = self.get_app_config(app_label)
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/apps/registry.py", line 163, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'polls'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/contrib/admin/apps.py", line 24, in ready
self.module.autodiscover()
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/utils/module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/contrib/auth/admin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 21, in <module>
UserModel = get_user_model()
File "/opt/theapp/venv3.8/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 161, in get_user_model
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'polls.User' that has not been installed
(venv3.8) ubuntu@ip-172-26-5-79:~/mysite$
有错误:.ImproperlyConfigured:AUTH_USER_MODEL 引用尚未安装的模型“polls.User”
因此,我们通过修改 mysite/settings.py 来解决此问题:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
对此:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
]
请注意,您需要添加的行是“polls”,它是您的 Django 应用程序的名称。
现在再试一次:
(venv3.8) ubuntu@ip-172-26-5-79:~/mysite$ python manage.py makemigrations
Migrations for 'polls':
polls/migrations/0001_initial.py
- Create model User
(venv3.8) ubuntu@ip-172-26-5-79:~/mysite$
成功!!!
所以这个长篇故事的重点是明确 Django 必须知道你的 Django 应用程序在哪里。您告诉 Django 的位置位于 settings.py 文件中的 INSTALLED_APPS 中。
这确实令人困惑 Django 项目和 Django 应用程序之间的区别,并且创建两个同名目录的奇怪建议使情况变得更糟。
相反,为了让事情更加清晰,我建议您在 Django 项目名称后添加“project”后缀,在 Django 应用程序名称后添加“app”后缀,并且不要为顶级目录指定与项目相同的名称。
这样就建立了一个新项目:
(venv3.8) ubuntu@ip-172-26-5-79:~$ mkdir container
(venv3.8) ubuntu@ip-172-26-5-79:~$ cd container/
(venv3.8) ubuntu@ip-172-26-5-79:~/container$ django-admin startproject myproject .
(venv3.8) ubuntu@ip-172-26-5-79:~/container$ ls
manage.py myproject
(venv3.8) ubuntu@ip-172-26-5-79:~/container$ python manage.py startapp myapp
(venv3.8) ubuntu@ip-172-26-5-79:~/container$ ls -lah
total 20K
drwxrwxr-x 4 ubuntu ubuntu 4.0K Oct 27 05:30 .
drwxr-xr-x 11 ubuntu ubuntu 4.0K Oct 27 05:29 ..
-rwxrwx--- 1 ubuntu ubuntu 665 Oct 27 05:30 manage.py
drwxrwxr-x 3 ubuntu ubuntu 4.0K Oct 27 05:30 myapp
drwxrwxr-x 3 ubuntu ubuntu 4.0K Oct 27 05:30 myproject
(venv3.8) ubuntu@ip-172-26-5-79:~/container$
现在,当您处理 Django 站点和 Django 项目时,您会更加清楚,并且您将不再因存在多个同名目录而感到困惑。
关于python - AUTH_USER_MODEL 指尚未安装的型号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26914022/
在了解如何检测用户设备后:iOS - How to get device make and model? 我制作了一个快速测试应用程序以根据设备显示警报。我没有从这段代码中得到任何警告。我在这里错过了
我有一个名为 test.rb 的模型,当我在 Controller 中使用 @tests=Test.new 时,出现以下错误。有人可以解决这个问题吗? “Test:Module 的未定义方法‘新’”
我必须从不同的网络服务和我自己的数据库中获取数据,并在网站上显示之前组合这些数据。 执行此操作的最佳方法是什么?我更喜欢为 Web 服务和数据库编写单独的模型。如何将不同数据源的模型类组织到不同的文件
我必须从不同的网络服务和我自己的数据库中获取数据,并在网站上显示之前组合这些数据。 执行此操作的最佳方法是什么?我更喜欢为 Web 服务和数据库编写单独的模型。如何将不同数据源的模型类组织到不同的文件
我正在开发一种模糊搜索机制。我在数据库(mysql)(英文和俄文名称)中有汽车品牌/型号和城市 - 大约 1000 项。用户可以输入错误或翻译中的单词。现在我从 db 中检索所有这些单词,并将循环中的
问题 我在一家拥有大量现场员工的公司工作,他们都配发了 iPhone。但这些手机的型号各不相同,没有早于 iPhone 4 的。我需要一种快速的方法来确定哪个人拥有哪种型号的 iPhone,因为该数据
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: Determine device (iPhone, iPod Touch) with iPhone SDK H
我有我的应用程序的故障转储。我的应用程序失败,因为一些用户说“无效指令”试图执行我在那里的一些 SSSE 指令。 在 WinDBG 中,如何找出 CPU 型号,以便找出其指令集,并支持该指令集,或更新
这是我的想法(原谅 Django 格式): class VehicleMake(Model): name = CharField(max_length=50) class VehicleMod
我知道 before_filter 仅适用于 Rails 中的 Controller ,但我想要一个模型这样的东西:每当我的模型中的一个方法被调用时,我想运行一个方法来确定被调用的方法是否应该运行。从
我按以下方式编写代码 #define isiPhone6 ( [[UIScreen mainScreen] bounds].size.height == 667)?TRUE:FALSE #define
我正在使用 Apache Mahout 解决二进制分类问题。我使用的算法是 OnlineLogisticRegression,我目前拥有的模型强烈倾向于产生 1 或 0 的预测,没有任何中间值。 请提
我正在使用 mysql 查询返回适合 php 中某些汽车的产品数组,如下所示; array { [0]=> array(3) { ["sku"]=> string(16) "123a "
有谁知道在 Android 下获取绑定(bind)蓝牙设备的制造商和型号的方法吗?例如,如果我与蓝牙耳机配对,我希望能够确定该耳机的制造商和型号。 谢谢! 最佳答案 目前在 Android 中没有公共
如果我有 3 个模型要连接怎么办? 例如: 用户可以对许多不同的应用程序拥有许多不同的权限。 所以我需要一个表来存储: user_id permission_id application_id has
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我正在尝试为 XS Max 定制设计。之前我只是通过检查 main.bound.screen.height 来识别设备,对于 XS Max,根据此网站:https://www.paintcodeapp
如果我使用 ng-model 作为输入字段并将其清空,则 Angular 将其设置为 '' 而不是 null,即使它之前为 null。 这对我来说是一个问题,因为如果输入字段为空,我需要将 null
我需要获取型号,例如:对于 iPhone 6,我想要的型号是 N61AP 而不是 iPhone 7,2。我在objective-c中需要这个。 我尝试了一些方法,但我得到的只是'iPhone 7,2'
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我是一名优秀的程序员,十分优秀!