RuntimeError:模型类models.AuthGroup没有在INSTALLED_APPS

时间:2017-07-20 07:44:57

标签: python django

我正在使用djnago 11.1,python 2.7和mongokit.i正在使用mongodb和sql database制作django的应用程序。首先,我做了与sql相关的编码,我的应用程序运行良好。但在为mongodb编码后,它显示了这个错误: -

经过十几个小时的故障排除,可能更多,我以为我终于开展业务了,但后来我得到了:

命令提示符 -

(orahienv) somya@somya-Inspiron-15-3555:~/Desktop/backup/admin_python$ python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x7fa8ce735de8>
Traceback (most recent call last):
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/somya/Desktop/backup/admin_python/admin_python/urls.py", line 21, in <module>
    url(r'', include('admin_app.urls', namespace = 'admin_app')),
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/somya/Desktop/backup/admin_python/admin_app/urls.py", line 26, in <module>
    exec "from {0} import {1}".format(dir_name + files.split(".")[0], files.split(".")[0].title())
  File "<string>", line 1, in <module>
  File "/home/somya/Desktop/backup/admin_python/admin_app/views_cluster/Travel_Details.py", line 30, in <module>
    from models import Location
  File "/home/somya/Desktop/backup/admin_python/models.py", line 15, in <module>
    class AuthGroup(models.Model):
  File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/base.py", line 118, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class models.AuthGroup doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

网上几乎没有这方面的信息,没有任何解决方案解决了我的问题。任何建议都会非常感激

setting.py -

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'admin_app',
    'celery',

admin_python / model.py -

 from __future__ import unicode_literals
    from django.db import models
    from django.utils import timezone
    from django.contrib.auth.signals import user_logged_in
    import hashlib, os
    from django.template.defaultfilters import default
    from django.core.signals import setting_changed
    from django.core.validators import MinValueValidator
    import admin_python
    import admin_app
    from django.conf import settings
    from django.contrib.auth.models import BaseUserManager
    import string
    import random
    import datetime
    from django_mongokit import connection
    from django_mongokit.document import DjangoDocument


    class Acsum(models.Model):
        sum_from = models.IntegerField(blank=True, null=True)
        sum_to = models.IntegerField(blank=True, null=True)
        sum_date = models.DateTimeField(blank=True, null=True)
        sum_amount = models.FloatField(blank=True, null=True)
        sum_type = models.CharField(max_length=12, blank=True, null=True)
        sum_reason = models.CharField(max_length=250, blank=True, null=True)
        dd = models.IntegerField(db_column='ID', blank=True, null=True)  # Field name made lowercase.
        balance = models.CharField(max_length=100, blank=True, null=True)
        tr_date = models.BigIntegerField(blank=True, null=True)
        tr_month = models.BigIntegerField(blank=True, null=True)
        tr_year = models.BigIntegerField(blank=True, null=True)

        class Meta:
            managed = False
            db_table = 'acsum'

    class Location(DjangoDocument):
      collection_name = 'location'
      __database__ = 'pom'
      structure = {
        'user_id':int,
        'name':basestring,
        'loc_lon': float,
        'timestamp':datetime.datetime,
        'activity':basestring,
        'lot_lat':float,
        'battery_status':basestring,
        'address':basestring,
        'date_created':datetime.datetime


     }

    use_dot_notation = True 

1 个答案:

答案 0 :(得分:0)

您的项目结构出现了严重错误。

import admin_python
import admin_app

这两个独立的应用程序?如果是,那么为什么你有.../admin_python/admin_app/...路径?

如果models.py位于admin_python目录下,则需要执行以下操作

  • admin_python添加到INSTALLED_APPS
  • 将以下内容添加到所有型号
class Meta:  
    app_label = "admin_python"

原因通常是模型存在于标准位置之外