I'm currently trying to upgrade an existing django-cms site from 3.0.16 to 3.1.4 with django 1.7.11
I followed the instructions given in http://docs.django-cms.org/en/latest/upgrade/3.1.html but when I get to python manage.py migrate
I get the following error:
django.db.utils.OperationalError: (1054, "Unknown column 'cms_page.path' in 'field list'")
Any hints on how I can debug this? Thanks!
Update:
Here is the full traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/path/to/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/path/to/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/path/to/venv/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/path/to/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/path/to/venv/local/lib/python2.7/site-packages/debug_toolbar/apps.py", line 15, in ready
dt_settings.patch_all()
File "/path/to/venv/local/lib/python2.7/site-packages/debug_toolbar/settings.py", line 228, in patch_all
patch_root_urlconf()
File "/path/to/venv/local/lib/python2.7/site-packages/debug_toolbar/settings.py", line 216, in patch_root_urlconf
reverse('djdt:render_panel')
File "/path/to/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 522, in reverse
app_list = resolver.app_dict[ns]
File "/path/to/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
self._populate()
File "/path/to/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 269, in _populate
for pattern in reversed(self.url_patterns):
File "/path/to/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 372, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/path/to/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 366, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/path/to/project/project/urls.py", line 14, in <module>
url(r'^admin/', include(admin.site.urls)),
File "/path/to/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 262, in urls
return self.get_urls(), self.app_name, self.name
File "/path/to/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 246, in get_urls
url(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), include(model_admin.urls))
File "/path/to/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 598, in urls
return self.get_urls()
File "/path/to/venv/local/lib/python2.7/site-packages/cms/admin/placeholderadmin.py", line 138, in get_urls
from cms.urls import SLUG_REGEXP
File "/path/to/venv/local/lib/python2.7/site-packages/cms/urls.py", line 20, in <module>
urlpatterns = get_app_patterns()
File "/path/to/venv/local/lib/python2.7/site-packages/cms/appresolver.py", line 215, in get_app_patterns
for title in title_qs.exclude(page__application_urls=None).exclude(page__application_urls='').order_by('-page__path').select_related():
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 141, in __iter__
self._fetch_all()
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all
self._result_cache = list(self.iterator())
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 701, in results_iter
for rows in self.execute_sql(MULTI):
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 787, in execute_sql
cursor.execute(sql, params)
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/path/to/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 129, in execute
return self.cursor.execute(query, args)
File "/path/to/venv/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/path/to/venv/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.OperationalError: (1054, "Unknown column 'cms_page.path' in 'field list'")
I'm not sure why this worked, but the traceback indicated that there was some problem in my projects urls.py
I commented out all of the url rules in this file, migrated the cms app, then uncommented my url rules. That seems to solve the migration problem.
Related
I'm upgrading a Django project from 1.8 to 1.9,
I deleted the database file and all cache files, then I tried to run
python manage.py migrate
or
python manage.py migrate --run-syncdb
but always raise this error django.db.utils.OperationalError: no such table:
here is the full traceback
Traceback (most recent call last):
File "manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/home/basha/UpgradeMloss/venv1.9/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/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 10, in check_url_config
return check_resolver(resolver)
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 19, in check_resolver
for pattern in resolver.url_patterns:
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/basha/UpgradeMloss/venv1.9/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/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/basha/UpgradeMloss/venv1.9/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/basha/UpgradeMloss/mloss/urls.py", line 30, in <module>
(r'^community/', include('community.urls')),
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 52, 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/basha/UpgradeMloss/mloss/community/urls.py", line 32, in <module>
'extra_context' : get_latest_news()
File "/home/basha/UpgradeMloss/mloss/community/summary.py", line 68, in get_latest_news
latest_posts = get_latest_posts()
File "/home/basha/UpgradeMloss/mloss/community/summary.py", line 32, in get_latest_posts
for forum in all_forums:
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 852, in execute_sql
cursor.execute(sql, params)
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/basha/UpgradeMloss/venv1.9/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/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/basha/UpgradeMloss/venv1.9/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 323, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: community_forum
it works fine on django1.8 without any error!
Are there any edits or updates should I make in Settings.py?
This question isn't related to your upgrade. You have a query inside your urls.py, where you do 'extra_context' : get_latest_news(). That executes as soon as the URLs are imported; so the migrations can never have a chance to run.
Note that as well as blocking the migrations, this code would give you out-of-date results, for the same reason: it is executed on import, not when the request is run. Remove that query and move it into the view itself.
Nevertheless, you really shouldn't have deleted the database, or the migration files.
After python3 manage.py makemigrations or python manage.py makemigrations
I did python3 manage.py migrate --fake or python manage.py migrate --fake.
It somehow worked. I did this fake migration after that I had commented out a ForeignKey, the model to the ForeignKey and the model in admin.py. I then went and looked in the admin, and the ForeignKey model was gone. So I did add that ForeignKey, model and admin.site.register back and did a real migration, the error was gone.
I have an existing Django 1.6 application that is using South.
I now need to add the Django admin application to the existing Django app. After adding the relevant admin entries into INSTALLED_APPS when I run syncdb the following error is shown:
django.db.utils.ProgrammingError: (1146, u"Table
'databasename.auth_permission' doesn't exist")
Removing South from the list of installed apps allows syncdb to successfully create the tables.
Is there any way to avoid removing south from the installed apps list just to install the Django Admin tables?
Admin was added by editing settings.py
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'THE ORIGINAL APPS ARE HERE',
'south',
The trackback is:
Syncing...
Creating tables ...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "path/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "path/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "path/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "path/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "path/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "path/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 92, in handle_noargs
syncdb.Command().execute(**options)
File "path/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "path/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "path/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "path/lib/python2.7/site-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
interactive=interactive, db=db)
File "path/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
response = receiver(signal=self, sender=sender, **named)
File "path/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 93, in create_permissions
"content_type", "codename"
File "path/lib/python2.7/site-packages/django/db/models/query.py", line 96, in __iter__
self._fetch_all()
File "path/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
self._result_cache = list(self.iterator())
File "path/lib/python2.7/site-packages/django/db/models/query.py", line 1071, in iterator
for row in self.query.get_compiler(self.db).results_iter():
File "path/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
for rows in self.execute_sql(MULTI):
File "path/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "path/lib/python2.7/site-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "path/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "path/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "path/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "path/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "path/lib/python2.7/site-packages/pymysql/cursors.py", line 102, in execute
result = self._query(query)
File "path/lib/python2.7/site-packages/pymysql/cursors.py", line 202, in _query
conn.query(q)
File "path/lib/python2.7/site-packages/pymysql/connections.py", line 734, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "path/lib/python2.7/site-packages/pymysql/connections.py", line 845, in _read_query_result
result.read()
File "path/lib/python2.7/site-packages/pymysql/connections.py", line 1048, in read
first_packet = self.connection._read_packet()
File "path/lib/python2.7/site-packages/pymysql/connections.py", line 826, in _read_packet
packet.check_error()
File "path/lib/python2.7/site-packages/pymysql/connections.py", line 373, in check_error
raise_mysql_exception(self.__data)
File "path/lib/python2.7/site-packages/pymysql/err.py", line 117, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "path/lib/python2.7/site-packages/pymysql/err.py", line 110, in _check_mysql_exception
raise errorclass(errno,errorvalue)
django.db.utils.ProgrammingError: (1146, u"Table 'databasename.auth_permission' doesn't exist")
I have an actions.py file which defines custom actions for the admin page for one of my models. It uses an intermediary page (like the default delete action) and hence has a corresponding form which is also declared in the same file.
For some reason, I had drop by database (development) and now when I try to run syncdb, it gives me the following error:
Traceback (most recent call last):
File "/home/vinayak/pyCharm/helpers/pycharm/django_manage.py", line 23, 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/vinayak/zenatix/customuser/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 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, 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 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/models.py", line 63, in <module>
patch_root_urlconf()
File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf
reverse('djdt:render_panel')
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 480, in reverse
app_list = resolver.app_dict[ns]
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 310, in app_dict
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 262, in _populate
for pattern in reversed(self.url_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 346, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 341, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/vinayak/zenatix/customuser/customuser/urls.py", line 6, in <module>
admin.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
import_module('%s.admin' % app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/vinayak/zenatix/customuser/iiitd/admin.py", line 3, in <module>
from actions import grant_read_permission
File "/home/vinayak/zenatix/customuser/iiitd/actions.py", line 13, in <module>
class SelectUserForm(forms.Form):
File "/home/vinayak/zenatix/customuser/iiitd/actions.py", line 16, in SelectUserForm
clientObj = ClientInfo.objects.all()[:1].get()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 781, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "iiitd_clientinfo" does not exist
LINE 1: ...ientinfo"."id", "iiitd_clientinfo"."corp_id" FROM "iiitd_cli...
iiitd is the name of one of my apps. The reason this is happening is because actions.py imports the iiitd_clientinfo model - but that doesn't exist yet, obviously. Currently, I make it work by excluding/commenting out my actions.py file. Surely, there has to be a work around?
I have tried the following:
south migration before syncdb - same error.
sorted out the INSTALLED_APPS order to ensure that they are in a topological order- same error
Used this in my actions.py:
try:
clientObj = ClientInfo.objects.all()[:1].get()
except ClientInfo.DoesNotExist:
clientObj = None
EDIT:
Relevent part of actions.py:
from django import forms, template
from django.contrib import admin
from django.contrib.admin import helpers
from django.shortcuts import render_to_response
from django.utils.encoding import force_unicode
from guardian.shortcuts import assign_perm
from django.utils.translation import ugettext as _
from models import ClientInfo
from customauth.models import ZenatixUser
class SelectUserForm(forms.Form):
_selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
try:
clientObj = ClientInfo.objects.all()[:1].get()
except ClientInfo.DoesNotExist:
clientObj = None
if clientObj:
client = clientObj.corp
client_name = client.shortName
client_id = client.cID
userList = ZenatixUser.objects.filter(corp__cID=client_id)
user = forms.ModelMultipleChoiceField(userList, label=client_name + ' users ')
def grant_read_permission(modeladmin, request, queryset):
Fix
class SelectUserForm(forms.Form):
_selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
def __init__(self, initial, *args, **kwargs):
super(SelectUserForm, self).__init__(*args, **kwargs)
try:
clientObj = ClientInfo.objects.all()[:1].get()
client = clientObj.corp
client_name = client.shortName
client_id = client.cID
userList = ZenatixUser.objects.filter(corp__cID=client_id)
#user = forms.ModelMultipleChoiceField(userList, label=client_name + ' users ')
self.fields['user'] = forms.ModelMultipleChoiceField(userList, label=client_name + ' users ')
self._selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
except ClientInfo.DoesNotExist:
raise Exception('Please add a client info object to the client')
It's mostly a wild guess until you post the source for your actions.py module, but from the traceback I assume line 16 is at the top level of your SelectUserForm class body. If so, this statement will be executed each time the module is imported, which is a BadThing for many reasons. You just discovered one of these reasons, congrats. Another one is that this will be executed once per process, and only once per process, which leads to to strange bugs as soon as you're in production (stale state, incoherent state from one process to another, etc).
The cure here is to move this statement within a method of your form.
I have django.contrib.auth in my installed apps and everything was was working about 10 minutes ago. I deleted the existed database because I had problems with south migrations. When I try to rebuild it I get an error.
Error: django.db.utils.DatabaseError: no such table: auth_user
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/bruk/workspace/hungryDroid/src/hungryDroid/Ingredient/models.py", line 22, in <module>
class Ingredient(models.Model):
File "/home/bruk/workspace/hungryDroid/src/hungryDroid/Ingredient/models.py", line 26, in Ingredient
FKowner = models.ForeignKey(User, default=User.objects.get(pk=1).id)
File "/usr/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 342, in get
num = len(clone)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 80, in __len__
self._result_cache = list(self.iterator())
File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 271, in iterator
for row in compiler.results_iter():
File "/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 677, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 732, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.7/site-packages/django/db/backends/util.py", line 15, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 200, in execute
return Database.Cursor.execute(self, query, params)
**django.db.utils.DatabaseError: no such table: auth_user**
The problem is that you are running a query against the User model
File "/home/bruk/workspace/hungryDroid/src/hungryDroid/Ingredient/models.py", line 26, in Ingredient
FKowner = models.ForeignKey(User, default=User.objects.get(pk=1).id)
In the syncdb process (during field declaration actually, so any time your module is imported, like during this validation process).
This will make sure that the auth_user query is executed before the auth_user table is created.
A safer way to get the functionality with the default user is to do
def get_default_user():
return User.objects.get(pk=1)
And then in your field declaration, do
FKowner = models.ForeignKey(User, default=get_default_user)
As per the model field reference default can be a callable. Note that you would have the same problem if you used get_default_user() in there - then it executes immediately, not on-demand.
I have a new server just installed. Everything seems to be fine but when i run:
python manage.py syncdb
it generates follow error:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/lib/python2.6/site-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/lib/python2.6/site-packages/django/contrib/auth/management/__init__.py", line 51, in create_permissions
content_type=ctype
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 138, in create
return self.get_query_set().create(**kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 360, in create
obj.save(force_insert=True, using=self.db)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 553, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 1436, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 791, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/usr/lib/python2.6/site-packages/MySQLdb/cursors.py", line 175, in execute
if not self._defer_warnings: self._warning_check()
File "/usr/lib/python2.6/site-packages/MySQLdb/cursors.py", line 89, in _warning_check
warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Incorrect string value: '\xE6\x99\xAF\xE9\xBB\x9E...' for column 'name' at row 1
All the tables and fields, in fact, created automatically without observable problem. I just wanna get rid of this error becoz the same thing does not happen in my old server with exactly the same project running on it.
So I am answering it here so that other people can have answer of same problem:
As said by Bill Kary:
He have solved this himself. Change all the collation of ALL tables AND fields to utf (utf8_general_ci) stops the error beautifully.