django.db.utils.OperationalError: no such table - python

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.

Related

ProgrammingError: relation 'blah blah' does not exist, trying to run the specific migration and get error

I am getting an error:
$ python manage.py migrate swsite 0023_hitcounter.py
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/lib64/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/lib64/python2.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/lib64/python2.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/lib64/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib64/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib64/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib64/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/www/swlab-website/mysite/urls.py", line 25, in <module>
url(r'^swsite/', include('swsite.urls')),
File "/usr/lib64/python2.7/site-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/www/swlab-website/swsite/urls.py", line 2, in <module>
from . import views
File "/var/www/swlab-website/swsite/views.py", line 27, in <module>
class IndexView(generic.ListView):
File "/var/www/swlab-website/swsite/views.py", line 31, in IndexView
newhit = HitCounter.objects.create()
File "/usr/lib64/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/django/db/models/query.py", line 401, in create
obj.save(force_insert=True, using=self.db)
File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 708, in save
force_update=force_update, update_fields=update_fields)
File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 736, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 820, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 859, in _do_insert
using=using, raw=raw)
File "/usr/lib64/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/django/db/models/query.py", line 1039, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib64/python2.7/site-packages/django/db/models/sql/compiler.py", line 1060, in execute_sql
cursor.execute(sql, params)
File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/lib64/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "swsite_hitcounter" does not exist
LINE 1: INSERT INTO "swsite_hitcounter" ("date", "template_location"...
This is confusing to me as it is specifically trying to build the swsite_hitcounter table as in the following migration I am trying to fun:
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2017-07-05 15:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('swsite', '0022_auto_20170307_1343'),
]
operations = [
migrations.CreateModel(
name='HitCounter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField(auto_now=True)),
('template_location', models.TextField()),
],
),
]
Is something maybe out of sink? This is me trying to run this migration on my production box, it ran fine (of course) on my development box. Might of been cause I ran a specific migration? :
python manage.py migrate swsite 0023_hitcounter.py
Though running:
python manage.py showmigrations
Gives me same error? I am guessing my migrations are out of sync but not being able to show migrations, I don't know how to show the ones that didn't get into this update (on production from gilab)
The traceback is showing you that the error is occuring in IndexView. You are trying to create objects in the database when the view loads.
class IndexView(TemplateView):
newhit = HitCounter.objects.create() # remove this line
...
Accessing the database when the views load like this is a bad idea, so you should probably remove the line. In production, it gives you the error because it is trying to create the object in the database before you have applied the migration that creates the table.

Django gets django.db.utils.ProgrammingError when starting tests

When I start tests I get error
~/work/some_project$ ./manage.py test
Raven is not configured (logging is disabled). Please see the documentation for more information.
/Users/ioganegambaputi/work/some_project/some_project/core/forms.py:7: RemovedInDjango19Warning: The django.forms.util module has been renamed. Use django.forms.utils instead.
from django.forms.util import ErrorList
/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/templated_email/__init__.py:2: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
from django.utils.importlib import import_module
/Users/ioganegambaputi/work/some_project/some_project/core/utils.py:50: RemovedInDjango19Warning: 'get_cache' is deprecated in favor of 'caches'.
self.cache = cache.get_cache(cache_alias or cache.DEFAULT_CACHE_ALIAS)
Creating test database for alias 'default'...
Got an error creating the test database: database "test_some_project" already exists
Type 'yes' if you would like to try deleting the test database 'test_some_project', or 'no' to cancel: yes
Destroying old test database 'default'...
/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py:229: RemovedInDjango19Warning: initial_data fixtures are deprecated. Use data migrations instead.
RemovedInDjango19Warning
Traceback (most recent call last):
File "./manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/test/runner.py", line 166, in setup_databases
**kwargs
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 368, in create_test_db
test_flush=not keepdb,
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 365, in sync_apps
hide_empty=True,
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/raven/contrib/django/management/__init__.py", line 37, in new_execute
return original_func(self, *args, **kwargs)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 60, in handle
self.loaddata(fixture_labels)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 90, in loaddata
self.load_label(fixture_label)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 147, in load_label
obj.save(using=self.using)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/core/serializers/base.py", line 173, in save
models.Model.save_base(self.object, using=using, raw=True)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/base.py", line 762, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/base.py", line 827, in _save_table
forced_update)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/base.py", line 877, in _do_update
return filtered._update(values) > 0
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/query.py", line 580, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1062, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/ioganegambaputi/work/env/some_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError
When I run my application on the localhost - all ok, it happens only with the test. This is my settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'some_project',
'USER': 'web',
'PASSWORD': '',
'HOST': ''
}
}
I use Django==1.8.4 and psql (PostgreSQL) 9.4.1.
I turned on database logs and nothing has been printed out on the console, but it works good when application normally running.
Also, I granted super user rights to the web user.
What is going wrong? How can I get more logs without debugging by hands?

Unknown column cms_page.path upgrading django-cms to 3.1

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.

Column 'django_migrations.id' has unsupported type 'serial' [ with Amazon Redshift]

I use django_celery with connecting to Amazon Redshift. To migrate database, after "makemigrations" I used command "python manage.py migrate" and error message show up as shown below.
The reason is Redshift does not support data type 'serial' but the 'django_migrations' table that contain 'serial' type is automatically created.
How to stop Django Migrations create this table or avoid using serial on 'django_migrations' table.
D:\code\test_celery_django>python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 441, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 47, in __init__
self.build_graph()
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 180, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 53, in ensure_schema
editor.create_model(self.Migration)
File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 286, in create_model
self.execute(sql, params or None)
File "C:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 111, in execute
cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.NotSupportedError: Column "django_migrations.id" has unsupported type "serial".
Are you trying to use Redshift as the backend database for your web application? That's a bad idea, Redshift is a data warehouse and as such individual query performance and latency are far from great, not to mention that Redshift doesn't enforce primary keys, which almost surely Django expects.
My recommendation, use PostgreSQL.

Django syncdb error

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.

Categories

Resources