Getting error in makemigrations - Django - python

When I'm typing python manage.py makemigrations I get
Traceback(most recent call last):
File "manage.py", line 10, in < module >
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 10 8, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name)
File "/var/www/project/app/app/places/models.py", line 13, in < module >
User = user_model()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py", line 150, in get_user_model return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 19 4, in get_model
self.check_models_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 13 1, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren 't loaded yet.
I've searched any solutions on many sites but nothing helps. Is it problem with project files or maybe something with django?

Related

Django manage.py runserver got AppRegistryNotReady: Models aren't loaded yet

I hit a problem when run django from command line with manage.py runserver.
The same code is fine with Django 1.5 several months ago.
Today I wanna pickup the code again and run upon Django 1.8.3 and python2.7.10 .
Now, got error here:
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/media/wni/study/workspace4320151111/weichun/mytheme/models.py", line 8, in <module>
from mezzanine.pages.models import Page
File "/media/wni/study/workspace4320151111/weichun/mezzanine/pages/models.py", line 34, in <module>
class Page(BasePage):
File "/media/wni/study/workspace4320151111/weichun/mezzanine/core/models.py", line 350, in __new__
return super(OrderableBase, cls).__new__(cls, name, bases, attrs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 298, in __new__
new_class.add_to_class(field.name, copy.deepcopy(field))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 226, in contribute_to_class
super(KeywordsField, self).contribute_to_class(cls, name)
File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 84, in contribute_to_class
cls._meta.get_fields_with_model()]:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 56, in wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 432, in get_fields_with_model
return [self._map_model(f) for f in self.get_fields()]
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 740, in get_fields
return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 802, in _get_fields
all_fields = self._relation_tree
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 60, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 709, in _relation_tree
return self._populate_directed_relation_graph()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 681, in _populate_directed_relation_graph
all_models = self.apps.get_models(include_auto_created=True)
File "/usr/local/lib/python2.7/dist-packages/django/utils/lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 168, in get_models
self.check_models_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Anyone knows how to fix it?
Thanks.
Wesley
I think you need to change your wsgi.py file as you go for different version of Django.
import os
import sys
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'YourAppName.settings'
application = WSGIHandler()
And try to comment all third party application imported in settings.py.
1] ./manage.py runserver will use your wsgi.py however it looks like the stack trace you've shown at the top does not include the wsgi file. Therefore the error is occurring before the wsgi file is loaded.
2] This could well be an issue with your Django settings. For example,may in LOGGING a filename in a non-existent directory.
3] or check this

Get errors trying to do python manage.py runserver

Catch errors trying to do manage.py runserver. GEOS has already installed. Database is created (I use PostgreSQL), all packages from requirements is successfully installed. When I run python manage.py runserver I get this messages.
(virualenv) C:\Users\Alexander\Desktop\myproject>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\core\management\__init__.py", line 312, in execute
django.setup()
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\contrib\auth\models.py", line 41, in <module>
class Permission(models.Model):
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\db\models\base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\db\models\base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\db\models\options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\db\utils.py", line 240, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\contrib\gis\db\backends\postgis\base.py", line 8, in <module>
from .features import DatabaseFeatures
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\contrib\gis\db\backends\postgis\features.py", line 1, in <module>
from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\contrib\gis\db\backends\base\features.py", line 3, in <module>
from django.contrib.gis.db.models import aggregates
File "C:\Users\Alexander\Desktop\myproject\virualenv\lib\site-packages\django\contrib\gis\db\models\__init__.py", line 12, in <module>
"See also https://docs.djangoproject.com/en/%s/ref/contrib/gis/install/geolibs/" % get_docs_version())
django.core.exceptions.ImproperlyConfigured: GEOS is required and has not been detected. Are you sure it is installed? See also https://docs.djangoproject.com/en/1.8/ref/contrib/gis/install/geolibs/
Any ideas how to solve it?
UPD: result of pip freeze:
(virualenv) C:\Users\Alexander\Desktop\myproject>pip freeze
amqp==1.4.9
anyjson==0.3.3
beautifulsoup4==4.1.3
billiard==3.3.0.23
bleach==1.4.1
boto==2.0
celery==3.1.23
chardet==2.3.0
Django==1.8.2
django-ajax-selects==1.3.6
django-appconf==1.0.2
django-celery==3.1.17
django-celery-email==1.1.4
django-contrib-comments==1.6.1
django-datatable-view==0.8.3
django-debug-toolbar==1.3.0
django-extensions==1.5.5
django-filter==0.10.0
django-formtools==1.0
django-grappelli==2.6.5
django-haystack==2.4.0
django-liststyle==0.2a0
django-multiselectfield==0.1.3
django-nocaptcha-recaptcha==0.0.18
django-postman==3.2.2
django-registration-redux==1.2
django-schedule==0.5b0
django-static-jquery==2.1.4
django-tagging==0.4
djangorestframework==3.1.2
docopt==0.4.0
ecdsa==0.13
elasticsearch==1.7.0
Fabric==1.10.1
filebrowser-safe==0.3.8
future==0.9.0
geopy==1.10.0
grappelli-safe==0.3.13
html5lib==0.99999
ipython==3.1.0
jsonfield==1.0.3
kombu==3.0.35
mailchimp==2.0.9
Mezzanine==4.1.0
mutagen==1.29
oauthlib==0.7.2
opbeat==3.0.2
paramiko==1.15.2
Pillow==2.8.1
psycopg2==2.6
pyactiveresource==2.1.1
pycrypto==2.6.1
pygeocoder==1.1.4
pysolr==3.3.2
python-dateutil==2.4.2
python-ptrace==0.8.1
pytz==2015.4
PyYAML==3.11
requests==2.7.0
requests-oauthlib==0.5.0
ShopifyAPI==2.1.3
six==1.9.0
sqlparse==0.1.15
tzlocal==1.0
urllib3==1.16
vobject==0.6.6
Werkzeug==0.10.4

ImportError under admin.autodiscover() when trying to run single django-nose test

I'm trying to run single test using django-nose:
./manage.py test lead.tests:LeadStatTests.basic_stat_test
And following ImportError occurs:
======================================================================
ERROR: Failure: ImportError (cannot import name LeadSource)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/loader.py", line 420, in loadTestsFromName
addr.filename, addr.module)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/kolen/items/someproject/lead/tests.py", line 16, in <module>
from lead.models import Lead, Action, LeadSource, LeadType, events_by_month, EventSummary
File "/Users/kolen/items/someproject/lead/models.py", line 38, in <module>
User = get_user_model()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 127, in get_user_model
user_model = get_model(app_label, model_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 271, in get_model
self._populate()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/debug_toolbar/models.py", line 63, in <module>
patch_root_urlconf()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 507, in reverse
app_list = resolver.app_dict[ns]
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
self._populate()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 267, in _populate
for pattern in reversed(self.url_patterns):
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 365, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/items/someproject/system/urls.py", line 8, in <module>
admin.autodiscover()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
import_module('%s.admin' % app)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/items/someproject/lead/admin.py", line 5, in <module>
from lead.models import LeadSource, LeadType, Lead, ........, \
ImportError: cannot import name LeadSource
Running all tests with ./manage.py test works. This exception occurs only when trying to run single test or test class. However running all tests takes too much time so I want a way to run single test.
Application and django admin works too. There's no __init__.py in root directory of the project.
Suddenly discovered that problem is caused by django-debug-toolbar. Removing it from the project solved this issue.
There is possibly duplicate of this question with similar problem also caused by django-debug-toolbar.

Trouble building/starting sentry and its database

Sentry
I've been using this to setup the environment: Sentry Setup
But when I get to this command:
sentry --config=/etc/sentry.conf.py upgrade
It gives me this error:
nope#not_telling_you-ubuntu:~/scratch$ sudo sentry --config=/etc/sentry.conf.py upgrade
Traceback (most recent call last):
File "/usr/local/bin/sentry", line 9, in <module>
load_entry_point('sentry==5.4.5', 'console_scripts', 'sentry')()
File "/usr/local/lib/python2.7/dist-packages/sentry-5.4.5-py2.7.egg/sentry/utils/runner.py", line 197, in main
initializer=initialize_app,
File "/usr/local/lib/python2.7/dist-packages/logan/runner.py", line 162, in run_app
management.execute_from_command_line([runner_name, command] + command_args)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 252, in fetch_command
app_name = get_commands()[subcommand]
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 101, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 93, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/logan/importer.py", line 68, in load_module
return self._load_module(fullname)
File "/usr/local/lib/python2.7/dist-packages/logan/importer.py", line 92, in _load_module
load_settings(self.config_path, allow_extras=self.allow_extras, settings=settings_mod)
File "/usr/local/lib/python2.7/dist-packages/logan/settings.py", line 49, in load_settings
execfile(mod_or_filename, conf.__dict__)
File "/etc/sentry.conf.py", line 45, in <module>
dgin
django.core.exceptions.ImproperlyConfigured: NameError("name 'dgin' is not defined",)
asdas#asdas-ubuntu:~/scratch$
Any idea what could be going on? I've setup everything until this point.
"dgin" is an undefined variable in the sentry configuration
It's likely this is a mistype or something similar, but that's what the error means.

Getting error for ManytoMany in django?

When I am trying to validate, I am getting this error.
python manage.py validate
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/validate.py", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/google/Myfiles/cheeserater/../cheeserater/packages/models.py", line 4, in <module>
class Package(models.Model):
File "/usr/local/google/Myfiles/cheeserater/../cheeserater/packages/models.py", line 11, in Package
categories = models.ManytoManyField(Category,related_name="packages")
AttributeError: 'module' object has no attribute 'ManytoManyField'
You have a typo:
categories = models.ManyToManyField
You have a typo in ManytoManyField,
It should be ManyToManyField.

Categories