KeyError: 'default'

544 views
Skip to first unread message

Mike Dewhirst

unread,
Apr 6, 2015, 8:44:01 AM4/6/15
to django...@googlegroups.com
Can someone please explain what KeyError: 'default' means?

This is the first time I have tried Django 1.7 and without doing any
migrations all I have done here is this ...

(xxex3) C:\Users\mike\env\xxex3\ssds>copy
substance\fixtures\test_data.json substance\fixtures\initial_data.json

(xxex3) C:\Users\mike\env\xxex3\ssds>python manage.py test
--settings=ssds.settings.test --verbosity=1 common refer substance
company workplace credit

Python: 3.4
Django: 1.7.7
17:40:04
SQLite3: memory

Creating test database for alias 'default'...
Traceback (most recent call last):
File
"C:\Users\mike\env\xxex3\lib\site-packages\django\contrib\contenttypes\models.py",
line 19, in get_by_natural_key
ct = self.__class__._cache[self.db][(app_label, model)]
KeyError: 'default'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py",
line 65, in execute
return self.cursor.execute(sql, params)
File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\sqlite3\base.py",
line 485, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: django_content_type

(there is more but the bottom line is ...)

return Database.Cursor.execute(self, query, params)
django.core.serializers.base.DeserializationError: Problem installing
fixture 'C:\Users\
mike\env\xxex3\ssds\substance\fixtures\initial_data.json': no such
table: django_content_type

(xxex3) C:\Users\mike\env\xxex3\ssds>

From my settings ...

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'

#CACHES = {
# 'default': {
# 'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
# }
#}

The same error occurs whether CACHES is commented out or not.

Not sure where to look in the documentation.
https://docs.djangoproject.com/en/1.7/topics/http/sessions/ got me
thinking (out of my depth) about sessions and serialization.

It seems Django 1.7 (or maybe 1.8) removes the 'name' column from
content_types upon migration and the migrated tables crash Django 1.6
(naturally I suppose). That means I'm stuck on 1.6 until I can get
things going on 1.7 and/or 1.8.

Is it possible to run with 1.7 without migrating the Django apps?

Any help will be much appreciated

Thanks

Mike


Pavel Kuchin

unread,
Apr 6, 2015, 11:13:31 AM4/6/15
to django...@googlegroups.com
Hi Mike, 

I think the issue is that Django can't find your default DB settings.

Best regards, Pavel

понедельник, 6 апреля 2015 г., 15:44:01 UTC+3 пользователь Mike Dewhirst написал:

Mike Dewhirst

unread,
Apr 6, 2015, 10:06:54 PM4/6/15
to django...@googlegroups.com
On 7/04/2015 1:07 AM, Pavel Kuchin wrote:
> Hi Mike,
>
> I think the issue is that Django can't find your default DB settings.
> Please take a
> look: https://docs.djangoproject.com/en/1.8/ref/settings/#databases

Pavel

Thanks for responding. I have had that setting running since they were
first called for in release notes for 1.6 (I think) anyway, for quite a
long time. My test routine uses (settings.test) SQLite in memory as
follows ...

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": ":memory:",
"USER": "",
"PASSWORD": "",
"HOST": "",
"PORT": "",
},
}

In production (settings.base) it is ...

dbhost = getcreds('db.host', PROJECT)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': PROJECT,
'USER': dbhost[0],
'PASSWORD': dbhost[1],
'HOST': dbhost[2],
'PORT': dbhost[3],
}
}

Trying to run the tests in Postgres delivers the same error but with an
additional final line ...

return self.cursor.execute(sql, params)
django.core.serializers.base.DeserializationError: Problem installing
fixture
'C:\Users\mike\env\xxex3\ssds\substance\fixtures\initial_data.json':
relation "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...
^

In case that doesn't line up properly in the email, the caret is
positioned like this ...

FROM "django_co...
^

The dev server runs and the software (unmigrated) works. I just cannot
get my unit tests to run under 1.7. It is like the nightmare of finding
yourself naked in Times Square!

Mike

>
> Best regards, Pavel
>
> понедельник, 6 Ð°Ð¿Ñ€ÐµÐ»Ñ 2015 г., 15:44:01 UTC+3
> пользователь Mike Dewhirst Ð½Ð°Ð¿Ð¸Ñ Ð°Ð»:
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/240490f9-eaa3-4b54-ba93-237218357a87%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/240490f9-eaa3-4b54-ba93-237218357a87%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Flavia Missi

unread,
Apr 7, 2015, 6:49:12 AM4/7/15
to django...@googlegroups.com
Hi,

From Django 1.6 to Django 1.7 migration handling was added to Django, so I suppose you cannot run your project with 1.7 without performing the required changes. If you're using south, take a look here: https://docs.djangoproject.com/en/1.7/topics/migrations/#upgrading-from-south

Also, I see you're using sqlite3 for development, although this is very fast, it may have considerable differences from using Postgres. So I think it's a good idea to run your tests on postgres (at least on the CI).

Hope it helps.

Regards,
-
Flavia
@flaviamissi


> To post to this group, send email to django...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.

Mike Dewhirst

unread,
Apr 7, 2015, 7:06:24 PM4/7/15
to django...@googlegroups.com
On 7/04/2015 8:48 PM, Flavia Missi wrote:
> Hi,
>
> From Django 1.6 to Django 1.7 /migration**/handling was added to
> Django, so I suppose you cannot run your project with 1.7 without
> performing the required changes. If you're using south, take a look
> here:
> https://docs.djangoproject.com/en/1.7/topics/migrations/#upgrading-from-south

I haven't used South. All my table changes have been done manually to date.

The project actually works fine running under the dev server. The
software seems ok under 1.7.

The problem is the test suite won't get started.

My test process is ...

1. Copy a set of fixtures to initial_data.json

2. Run the tests

3. Delete initial_data.json

The fixtures exclude all tables except for some reference info which
must exist and would be too tricky to recreate from scratch each time.
Also, the reference data is part of some of the tests. So, I'm more or
less committed to using fixtures for testing.

Mike


>
> Also, I see you're using sqlite3 for development, although this is very
> fast, it may have considerable differences from using Postgres. So I
> think it's a good idea to run your tests on postgres (at least on the CI).

Yes I do that. SQLite in dev and Postgres for staging.

>
> Hope it helps.
>
> Regards,
> -
> Flavia
> @flaviamissi
>
> On Mon, Apr 6, 2015 at 11:06 PM Mike Dewhirst <mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au>> wrote:
>
> On 7/04/2015 1:07 AM, Pavel Kuchin wrote:
> > Hi Mike,
> >
> > I think the issue is that Django can't find your default DB settings.
> > Please take a
> > look:
> https://docs.djangoproject.__com/en/1.8/ref/settings/#__databases
> <https://docs.djangoproject.com/en/1.8/ref/settings/#databases>
>
> Pavel
>
> Thanks for responding. I have had that setting running since they were
> first called for in release notes for 1.6 (I think) anyway, for quite a
> long time. My test routine uses (settings.test) SQLite in memory as
> follows ...
>
> DATABASES = {
> Â Â Â "default": {
> Â Â Â Â Â "ENGINE": "django.db.backends.sqlite3",
> Â Â Â Â Â "NAME": ":memory:",
> Â Â Â Â Â "USER": "",
> Â Â Â Â Â "PASSWORD": "",
> Â Â Â Â Â "HOST": "",
> Â Â Â Â Â "PORT": "",
> Â Â Â Â Â },
> Â Â Â }
>
> In production (settings.base) it is ...
>
> dbhost = getcreds('db.host', PROJECT)
> DATABASES = {
> Â Â Â 'default': {
> Â Â Â Â Â 'ENGINE':Â Â 'django.db.backends.__postgresql_psycopg2',
> Â Â Â Â Â 'NAME':Â Â Â PROJECT,
> Â Â Â Â Â 'USER':Â Â Â dbhost[0],
> Â Â Â Â Â 'PASSWORD': dbhost[1],
> Â Â Â Â Â 'HOST':Â Â Â dbhost[2],
> Â Â Â Â Â 'PORT':Â Â Â dbhost[3],
> Â Â Â }
> }
>
> Trying to run the tests in Postgres delivers the same error but with an
> additional final line ...
>
> Â Â Â return self.cursor.execute(sql, params)
> django.core.serializers.base.__DeserializationError: Problem installing
> fixture
> 'C:\Users\mike\env\xxex3\ssds\__substance\fixtures\initial___data.json':
> relation "django_content_type" does not exist
> LINE 1: ..."."app_label", "django_content_type"."model" FROM
> "django_co...
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
> Â Â Â Â Â Â Â Â ^
>
> In case that doesn't line up properly in the email, the caret is
> positioned like this ...
>
> FROM "django_co...
> Â Â Â ^
>
> The dev server runs and the software (unmigrated) works. I just cannot
> get my unit tests to run under 1.7. It is like the nightmare of finding
> yourself naked in Times Square!
>
> Mike
>
> >
> > Best regards, Pavel
> >
> > à ¿à ¾à ½à µà ´à µà »ÑŒà ½à ¸à º, 6
> à °à ¿Ñ€à µà »Ñ 2015 à ³., 15:44:01 UTC+3
> > à ¿à ¾à »ÑŒà ·à ¾à ²à °Ñ‚à µà »ÑŒ Mike
> Dewhirst à ½à °à ¿à ¸Ñ à °à »:
> >
> >Â Â Â Can someone please explain what KeyError: 'default' means?
> >
> >Â Â Â This is the first time I have tried Django 1.7 and without
> doing any
> >Â Â Â migrations all I have done here is this ...
> >
> >Â Â Â (xxex3) C:\Users\mike\env\xxex3\ssds>__copy
> >Â Â Â substance\fixtures\test_data.__json
> substance\fixtures\initial___data.json
> >
> >Â Â Â (xxex3) C:\Users\mike\env\xxex3\ssds>__python manage.py test
> >Â Â Â --settings=ssds.settings.test --verbosity=1 common refer
> substance
> >Â Â Â company workplace credit
> >
> >Â Â Â Python:Â Â 3.4
> >Â Â Â Django:Â Â 1.7.7
> >Â Â Â 17:40:04
> >Â Â Â SQLite3:Â memory
> >
> >Â Â Â Creating test database for alias 'default'...
> >Â Â Â Traceback (most recent call last):
> >Â Â Â Â Â File
> >Â Â
> Â "C:\Users\mike\env\xxex3\lib\__site-packages\django\contrib\__contenttypes\models.py",
> >
> >Â Â Â line 19, in get_by_natural_key
> >Â Â Â Â Â Â ct = self.__class__._cache[self.db]__[(app_label,
> model)]
> >Â Â Â KeyError: 'default'
> >
> >Â Â Â During handling of the above exception, another exception
> occurred:
> >
> >Â Â Â Traceback (most recent call last):
> >Â Â Â Â Â File
> >Â Â
> Â "C:\Users\mike\env\xxex3\lib\__site-packages\django\db\__backends\utils.py",
> >
> >Â Â Â line 65, in execute
> >Â Â Â Â Â Â return self.cursor.execute(sql, params)
> >Â Â Â Â Â File
> >Â Â
> Â "C:\Users\mike\env\xxex3\lib\__site-packages\django\db\__backends\sqlite3\base.py",
> >
> >Â Â Â line 485, in execute
> >Â Â Â Â Â Â return Database.Cursor.execute(self, query, params)
> >Â Â Â sqlite3.OperationalError: no such table: django_content_type
> >
> >Â Â Â (there is more but the bottom line is ...)
> >
> >Â Â Â Â Â Â return Database.Cursor.execute(self, query, params)
> >Â Â Â django.core.serializers.base.__DeserializationError:
> Problem installing
> >Â Â Â fixture 'C:\Users\
> >Â Â
> Â mike\env\xxex3\ssds\substance\__fixtures\initial_data.json': no such
> >Â Â Â table: django_content_type
> >
> >Â Â Â (xxex3) C:\Users\mike\env\xxex3\ssds>
> >
> >Â Â Â Â From my settings ...
> >
> >Â Â Â SESSION_SERIALIZER =
> >Â Â Â 'django.contrib.sessions.__serializers.JSONSerializer'
> >
> >Â Â Â #CACHES = {
> >Â Â Â #Â Â 'default': {
> >Â Â Â #Â Â Â Â 'BACKEND':
> 'django.core.cache.backends.__dummy.DummyCache',
> >Â Â Â #Â Â }
> >Â Â Â #}
> >
> >Â Â Â The same error occurs whether CACHES is commented out or not.
> >
> >Â Â Â Not sure where to look in the documentation.
> >Â Â Â
> https://docs.djangoproject.__com/en/1.7/topics/http/__sessions/
> <https://docs.djangoproject.com/en/1.7/topics/http/sessions/>
> >Â Â
> Â <https://docs.djangoproject.__com/en/1.7/topics/http/__sessions/
> <https://docs.djangoproject.com/en/1.7/topics/http/sessions/>> got me
> >Â Â Â thinking (out of my depth) about sessions and serialization.
> >
> >Â Â Â It seems Django 1.7 (or maybe 1.8) removes the 'name'
> column from
> >Â Â Â content_types upon migration and the migrated tables crash
> Django 1.6
> >Â Â Â (naturally I suppose). That means I'm stuck on 1.6 until I
> can get
> >Â Â Â things going on 1.7 and/or 1.8.
> >
> >Â Â Â Is it possible to run with 1.7 without migrating the
> Django apps?
> >
> >Â Â Â Any help will be much appreciated
> >
> >Â Â Â Thanks
> >
> >Â Â Â Mike
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>
> > <mailto:django-users+...@googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>>.
> > To post to this group, send email to
> django...@googlegroups.com <mailto:django...@googlegroups.com>
> > <mailto:django-users@__googlegroups.com
> <mailto:django...@googlegroups.com>>.
> > Visit this group at http://groups.google.com/__group/django-users
> <http://groups.google.com/group/django-users>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/__msgid/django-users/240490f9-__eaa3-4b54-ba93-237218357a87%__40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/240490f9-eaa3-4b54-ba93-237218357a87%40googlegroups.com>
> >
> <https://groups.google.com/d/__msgid/django-users/240490f9-__eaa3-4b54-ba93-237218357a87%__40googlegroups.com?utm_medium=__email&utm_source=footer
> <https://groups.google.com/d/msgid/django-users/240490f9-eaa3-4b54-ba93-237218357a87%40googlegroups.com?utm_medium=email&utm_source=footer>>.
> > For more options, visit https://groups.google.com/d/__optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/__group/django-users
> <http://groups.google.com/group/django-users>.
> To view this discussion on the web visit
> https://groups.google.com/d/__msgid/django-users/55233B9F.__3040903%40dewhirst.com.au
> <https://groups.google.com/d/msgid/django-users/55233B9F.3040903%40dewhirst.com.au>.
> For more options, visit https://groups.google.com/d/__optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CADQG5okf_3Yzx9c8OdEwvuRNhSoNyLmVotwcwr%2BV_rN-fr%3D4aA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CADQG5okf_3Yzx9c8OdEwvuRNhSoNyLmVotwcwr%2BV_rN-fr%3D4aA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages