To give a bit of context, I'm working in internship on the upgrade of a Django app from 1.4.22 to 1.11 and python 2 to 3.
The project wasn't well factored, and when I tried to refactor it, I got a strange stack :
Traceback (most recent call last):
File "/home/antonin/Developpement/Projet/djangoproject2/djangoproject/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/antonin/Developpement/Projet/djangoproject2/djangoproject/instance/models.py", line 54, in <module>
YEARS += [(str(yr), _(u"n+%(year)d") % {'year': yr}) for yr in range(1, 20)]
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/functional.py", line 179, in __mod__
return six.text_type(self) % rhs
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/functional.py", line 144, in __text_cast
return func(*self.__args, **self.__kw)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 83, in ugettext
return _trans.ugettext(message)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 325, in ugettext
return do_translate(message, 'ugettext')
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 306, in do_translate
_default = translation(settings.LANGUAGE_CODE)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 209, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 195, in _fetch
res = _merge(apppath)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in _merge
t = _translation(path)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _translation
t = gettext_module.translation('django', path, [loc], DjangoTranslation)
File "/usr/lib64/python2.7/gettext.py", line 554, in translation
t = _translations.setdefault(key, class_(fp))
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 107, in __init__
gettext_module.GNUTranslations.__init__(self, *args, **kw)
File "/usr/lib64/python2.7/gettext.py", line 255, in __init__
self._parse(fp)
File "/usr/lib64/python2.7/gettext.py", line 348, in _parse
magic = unpack('<I', buf[:4])[0]
struct.error: unpack requires a string argument of length 4
When I tried to debug, with step by step mode, I saw that the issue is at the line
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 107, in __init__
gettext_module.GNUTranslations.__init__(self, *args, **kw)
where fp.read() receive a u'path/to/file.po' (path which is correct) and return a empty buffer. But I don't see any reasons why this appens.
Edit : thanks, håken, it was Indeed the .mo files that were corrupted. Problem solved.
Related
so I am doing a little project for a class with pythonanywhere.com
I am following the instructions given by the teacher, and I entered the following command in the virtualenv console:
python .../manage.py makemigrations
But I have this error message :
'cannot import name views'.
I also had similar error (such as cannot import path, etc...), but I was able to fix them searching on this website. Unfortunately, I didn't find any solution that worked for this particular problem.
So I'd like help to solve it. And I am also wondering if so many issues while trying to make a migration is normal ?
Thank you very much in advance.
Here is the urls.py file that seem to be the problem,
from django.conf.urls import url
from . import views
urlpatterns = [
url('', views.homepage, name='homepage'),
url('user', views.user.list, name='users-list'),
url('<user_id>', views.user.profile, name='user-profile'),
url('listing', views.listing.list, name='listings-list'),
url('<listing_id>', views.listing.profile, name='listing-profile'),
url('currency', views.currency.list, name='currencies-list'),
url('<currency_id>', views.currency.profile, name='currency-profile'),
]
And Here is the full stuff from the virtualenv console.
(django2) 16:28 ~ $ python /home/infosgr37a/project/manage.py makemigrations
Traceback (most recent call last):
File "/home/infosgr37a/project/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 353, in execute
self.check()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 303, 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/infosgr37a/project/mysite/urls.py", line 20, in <module>
url('', include('solvaycoin.urls')),
File "/usr/local/lib/python2.7/dist-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/infosgr37a/project/solvaycoin/urls.py", line 2, in <module>
from . import views
ImportError: cannot import name views
Full layout :
-Project/
---mysite/
---solvaycoin/
------migrations/
------static/
------templates/
------views/
------__init__.py
------__init__.pyc
------admin.py
------admin.pyc
------apps.py
------apps.pyc
------models.py
------models.pyc
------urls.py
------urls.pyc
---manage.py
So 'views' is a folder.
I hope this is clear enough, I didn't know how to do it properly.
Edit:
Tried what Babu recommended, and it got me post the 'view' problem.
But now I have another one:
(django2) 18:51 ~ $ python /home/infosgr37a/project/manage.py makemigrations
Traceback (most recent call last):
File "/home/infosgr37a/project/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 353, in execute
self.check()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 303, 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/infosgr37a/project/mysite/urls.py", line 20, in <module>
url('', include('solvaycoin.urls')),
File "/usr/local/lib/python2.7/dist-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/infosgr37a/project/solvaycoin/urls.py", line 5, in <module>
url('user', views.user.list, name='users-list'),
AttributeError: 'module' object has no attribute 'user'
Is it because I moved my views to a single file ?
There is no views.py in your solvaycoin application folder. Create views.py in your solvaycoin folder Paste your functions and class ('homepage', user.list, user.profile, listing.list, listing.profile, currency.list, currency.profile) inside that view.py file. Hope It Works.............!!!!!!!
Django-based project made use of Django 1.6 and now needs upgrade to 1.9. So i just renamed South's 'migrations' folders to 'south_migrations', created 'migrations' folder with init.py in each app that is in INSTALLED_APPS, upgraded all requirements of a project and made changes to code so it would be Django1.9-compatible. Now i want to create native Django migrations running 'makemigrations' but getting this traceback:
Traceback (most recent call last):
File "/home/nervosa/Apps/pycharm-2016.1/helpers/pycharm/django_manage.py", line 41, in <module>
run_module(manage_file, None, '__main__', True)
File "/usr/lib/python2.7/runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/nervosa/DjangoProjects/iticket/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, 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/nervosa/DjangoProjects/iticket/iticket/urls.py", line 7, in <module>
from frontend.views import ReturnPaymentURL
File "/home/nervosa/DjangoProjects/iticket/frontend/views.py", line 19, in <module>
from cases.forms import SelfTrafficForm, SelfStartTrafficForm, PJCForm
File "/home/nervosa/DjangoProjects/iticket/cases/forms.py", line 269, in <module>
class SelfTrafficForm(forms.ModelForm):
File "/home/nervosa/DjangoProjects/iticket/cases/forms.py", line 271, in SelfTrafficForm
counties = [(x.pk, x.county.title()) for x in County.objects.all()]
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/nervosa/DjangoProjects/virtualenvs/iticket_venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "places_county" does not exist
LINE 1: ...."main_attorney_id", "places_county"."ds_id" FROM "places_co...
^
When running for separate app, e.g. 'makemigrations billing' i get just the same output. I'm kinda puzzled because even Django's tables aren't created!!!
What is the best way to overcome this?
Your TrafficForm is doing something it shouldn't, which is querying the County objects at import time. While you had an existing database, this was OK(*), but now that you're starting from scratch it will complain.
You should change that form to use ModelChoiceField.
(*) it's almost always a bad idea to do this anyway, because new objects won't be visible in that field until the process is restarted; but in your case I guess new County objects are not often created.
I have project with multiple apps in it. One of the apps has a Contact model and a Supplier model. The Supplier has a OneToOne relation to the Contact model. Everything worked fine in Django 1.8.11. When I attempt to makemigrations or any other command, I get the following error.
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:\env\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "D:\env\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\env\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\env\lib\site-packages\django\core\management\base.py", line 398, in execute
self.check()
File "D:\env\lib\site-packages\django\core\management\base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "D:\env\lib\site-packages\django\core\checks\registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "D:\env\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "D:\env\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "D:\env\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\env\lib\site-packages\django\core\urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "D:\env\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\env\lib\site-packages\django\core\urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "D:\mdjango\mdjango\urls.py", line 32, in <module>
url(r'^parts?/', include('parts.urls')),
File "D:\env\lib\site-packages\django\conf\urls\__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "D:\mdjango\parts\urls.py", line 2, in <module>
from parts import views, ajax_views
File "D:\mdjango\parts\views.py", line 9, in <module>
from parts import forms
File "D:\mdjango\parts\forms.py", line 17, in <module>
class PartForm(forms.ModelForm):
File "D:\mdjango\parts\forms.py", line 20, in PartForm
class Meta:
File "D:\mdjango\parts\forms.py", line 26, in Meta
"/contacts/create/?next=/parts/create", "Add Supplier")
File "D:\mdjango\general\widgets.py", line 9, in __init__
super(SelectWithButton, self).__init__(attrs, choices)
File "D:\env\lib\site-packages\django\forms\widgets.py", line 514, in __init__
self.choices = list(choices)
File "D:\env\lib\site-packages\django\db\models\query.py", line 258, in __iter__
self._fetch_all()
File "D:\env\lib\site-packages\django\db\models\query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "D:\env\lib\site-packages\django\db\models\query.py", line 52, in __iter__
results = compiler.execute_sql()
File "D:\env\lib\site-packages\django\db\models\sql\compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "D:\env\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "D:\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "D:\env\lib\site-packages\django\db\utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "D:\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "contacts_supplier" does not exist
LINE 1: ...tacts_supplier"."default_contract_target_id" FROM "contacts_...
Basically, I have a URL file in my Parts app that is importing from parts.views, which is standard Django procedure. The parts.views file is importing from parts.forms, also standard Django procedure. The form that is causing issues is this:
class PartForm(forms.ModelForm):
class Meta:
model = Part
fields = ['supplier', 'number', 'name']
widgets = {
'supplier': SelectWithButton(None, Supplier.objects.all(),
"/contacts/create/?next=/parts/create", "Add Supplier")
}
Here's the SelectWithButton class:
from django.forms import Select
from django.template.loader import get_template
class SelectWithButton(Select):
def __init__(self, attrs=None, choices=(), btn_url='', btn_txt=''):
super(SelectWithButton, self).__init__(attrs, choices)
self.btn_url = btn_url
self.btn_txt = btn_txt
def render(self, name, value, attrs=None, choices=()):
context = {'href': self.btn_url, 'text': self.btn_txt,
'select_field': super(SelectWithButton, self).render(name, value, attrs, choices)}
t = get_template("general\selectWithButton.html")
return t.render(context)
The error seems to be that it is trying to get all the objects from Supplier before the migrations have been done. But I'm trying to make the migrations, and I'm getting this error. I did read that Django 1.9 now checks the URL files in the manage.py command, but it seems that I have done nothing out of the ordinary. You can read more here on the 1.9.3 page: https://docs.djangoproject.com/en/1.9/releases/1.9.3/
When I comment out the reference to SelectWithButton, I get a similar error on another form that has an autocomplete_light.MultipleChoiceField on it. What am I doing wrong? It works fine in Django 1.8.11.
Here is the other error and form:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:\env\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "D:\env\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\env\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\env\lib\site-packages\django\core\management\base.py", line 398, in execute
self.check()
File "D:\env\lib\site-packages\django\core\management\base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "D:\env\lib\site-packages\django\core\checks\registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "D:\env\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "D:\env\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "D:\env\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\env\lib\site-packages\django\core\urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "D:\env\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\env\lib\site-packages\django\core\urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "D:\mdjango\mdjango\urls.py", line 33, in <module>
url(r'^transactions?/', include('transactions.urls')),
File "D:\env\lib\site-packages\django\conf\urls\__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "D:\mdjango\transactions\urls.py", line 3, in <module>
from views import *
File "D:\mdjango\transactions\views.py", line 3, in <module>
from forms import *
File "D:\mdjango\transactions\forms.py", line 18, in <module>
class InventoryTransactionForm(forms.ModelForm):
File "D:\mdjango\transactions\forms.py", line 32, in InventoryTransactionForm
required=False)
File "D:\env\lib\site-packages\autocomplete_light\fields.py", line 74, in __init__
self.get_choices(autocomplete, registry, widget)})
File "D:\env\lib\site-packages\autocomplete_light\fields.py", line 82, in get_choices
return ((a.choice_value(c), a.choice_label(c)) for c in a.choices)
File "D:\env\lib\site-packages\django\db\models\query.py", line 258, in __iter__
self._fetch_all()
File "D:\env\lib\site-packages\django\db\models\query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "D:\env\lib\site-packages\django\db\models\query.py", line 52, in __iter__
results = compiler.execute_sql()
File "D:\env\lib\site-packages\django\db\models\sql\compiler.py", line 848, in execute_sql
cursor.execute(sql, params)
File "D:\env\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "D:\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "D:\env\lib\site-packages\django\db\utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "D:\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "parts_sns" does not exist
LINE 1: SELECT "parts_sns"."id", "parts_sns"."sn" FROM "parts_sns"
The form:
class InventoryTransactionForm(forms.ModelForm):
parent_sn = autocomplete_light.ModelChoiceField(label="Parent SN", autocomplete='InventoryParentSNAutocomplete',
required=False)
qty_in = forms.FloatField(label="In", required=False)
qty_out = forms.FloatField(label="Out", required=False)
notes = forms.CharField(required=False)
part = autocomplete_light.ModelChoiceField(autocomplete="StandardAutocomplete")
document = autocomplete_light.ModelChoiceField(autocomplete="OpenDocumentAutocomplete", required=False)
# for Qty Out serial numbers
sns = autocomplete_light.MultipleChoiceField(label="SNs", autocomplete='InventoryQtyOutSNsAutocomplete',
required=False)
user = forms.ModelChoiceField(Employee.objects.filter(user__is_active=True))
class Meta:
model = Transaction
fields = ['date', 'usage', 'notes', 'user', 'sns']
Your form is causing the Supplier.objects.all() queryset to be evaluated before the supplier table has been created in the database.
You can get around this by setting the widget in the form's __init__ method.
class PartForm(forms.ModelForm):
class Meta:
model = Part
fields = ['supplier', 'number', 'name']
def __init__(self, *args, **kwargs):
super(PartForm, self).__init__(*args, **kwargs)
self.fields['supplier'].widget = SelectWithButton(
None,
Supplier.objects.all(),
"/contacts/create/?next=/parts/create",
"Add Supplier",
)
unable to start C:\Python27\mysastha>python manage.py runserver
c:\python27\lib\site-packages\djangotoolbox-1.6.2-py2.7.egg\djangotoolbox\db\uti
ls.py:5: RemovedInDjango19Warning: django.utils.unittest will be removed in Djan
go 1.9.
from django.utils.unittest import skip
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\core\managemen
t\__init__.py", line 330, in execute_from_command_line
utility.execute()
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\core\managemen
t\__init__.py", line 304, in execute
django.setup()
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\__init__.py",
line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\apps\registry.
py", line 108, in populate
app_config.import_models(all_models)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\apps\config.py
", line 197, 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:\python27\lib\site-packages\django-1.8-py2.7.egg\django\contrib\auth\m
odels.py", line 40, in <module>
class Permission(models.Model):
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\base
.py", line 127, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\base
.py", line 303, in add_to_class
value.contribute_to_class(cls, name)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\opti
ons.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\__init__.py
", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\utils.py",
line 238, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\utils.py",
line 127, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an av
ailable database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'django_mongodb_engine', u'mysql', u'oracle', u'postgresql_psycopg2', u'sql
ite3'
Error was: cannot import name decimal_to_string
Just follow the instructions in the trace back. you need django.db.backends.django_mongodb_engine as the engine. Not just django_mongodb_engine.
If you havent already you will probably need a couple dependencies for the engine to work. im on mobile and dont know what they are called at the moment for mongodb
Why do I get this error when I run manage.py validate?:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\python26\lib\site-packages\django\core\management\__init__.py", line
438, in execute_manager
utility.execute()
File "C:\python26\lib\site-packages\django\core\management\__init__.py", line
379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\python26\lib\site-packages\django\core\management\base.py", line 191,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\python26\lib\site-packages\django\core\management\base.py", line 218,
in execute
output = self.handle(*args, **options)
File "C:\python26\lib\site-packages\django\core\management\base.py", line 347,
in handle
return self.handle_noargs(**options)
File "C:\python26\lib\site-packages\django\core\management\commands\validate.p
y", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "C:\python26\lib\site-packages\django\core\management\base.py", line 245,
in validate
num_errors = get_validation_errors(s, app)
File "C:\python26\lib\site-packages\django\core\management\validation.py", lin
e 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\python26\lib\site-packages\django\db\models\loading.py", line 146, in
get_app_errors
self._populate()
File "C:\python26\lib\site-packages\django\db\models\loading.py", line 61, in
_populate
self.load_app(app_name, True)
File "C:\python26\lib\site-packages\django\db\models\loading.py", line 78, in
load_app
models = import_module('.models', app_name)
File "C:\python26\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\projects\mysite\..\mysite\books\models.py", line 5, in <module>
class Publisher(models.Model):
File "C:\projects\mysite\..\mysite\books\models.py", line 6, in Publisher
name = models.CharField(maxlength=30)
File "C:\python26\lib\site-packages\django\db\models\fields\__init__.py", line
542, in __init__
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'maxlength'
The problem is that you are using a newer version of Django now. Since 1.0 (or actually, somewhere in 0.97) Django switched to max_length instead of maxlength. So either upgrade your code or install Django 0.96 for it to work again.
It's difficult to be 100% sure, because you haven't included the code in mysite/books/models.py, but it would appear that the 'max_length' keyword argument to a CharField in the Publisher class has been misspelled 'maxlength'.
See here for the correct values:
http://docs.djangoproject.com/en/dev/ref/models/fields/#charfield