2015-01-30 4 views
0

저는 장고를 처음 사용하고 홈페이지를 만들려고합니다. 하지만 이미 데이터베이스 설정에 문제가 있습니다. 내가 TypeError : unhashable type : 'bytearray'

python manage.py migrate 

를 실행하면이 오류를 내가 파이썬 3.4, 장고-1.7.4을 사용하고

(env) [email protected]:~/public_html/p_kreker$ python manage.py migrate 
Operations to perform: 
    Apply all migrations: auth, sessions, contenttypes, admin 
Running migrations: 
    Applying contenttypes.0001_initial... OK 
    Applying auth.0001_initial... OK 
    Applying admin.0001_initial... OK 
    Applying sessions.0001_initial... OK 
Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line 
    utility.execute() 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute 
    output = self.handle(*args, **options) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 165, in handle 
    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/core/management/sql.py", line 268, in emit_post_migrate_signal 
    using=db) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/dispatch/dispatcher.py", line 198, in send 
    response = receiver(signal=self, sender=sender, **named) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/contrib/auth/management/__init__.py", line 64, in create_permissions 
    if not is_latest_migration_applied('auth'): 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/loader.py", line 292, in is_latest_migration_applied 
    loader = MigrationLoader(connection) 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/loader.py", line 49, in __init__ 
    self.build_graph() 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/loader.py", line 184, in build_graph 
    self.applied_migrations = recorder.applied_migrations() 
    File "/home/paul/public_html/p_kreker/env/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 60, in applied_migrations 
    return set(tuple(x) for x in self.migration_qs.values_list("app", "name")) 
TypeError: unhashable type: 'bytearray' 

을 얻고 SQL 연결을위한 MySQL의 커넥터 - 파이썬 2.0.2. 이 프로젝트에서는 python 3 venv로 가상 환경을 만들었습니다. 나는이 프로젝트를 github에서 개최합니다 : https://github.com/pkreker/p_kreker

미리 감사드립니다!

편집 settings.py :

""" 
Django settings for p_kreker project. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.7/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/1.7/ref/settings/ 
""" 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
import os 
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = '@l)[email protected]*i+n2=1#kbf#nzqm6()c)dv116pqq^p' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

TEMPLATE_DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = (
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
) 

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
) 

ROOT_URLCONF = 'p_kreker.urls' 

WSGI_APPLICATION = 'p_kreker.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'NAME': 'p_kreker', 
     'ENGINE': 'mysql.connector.django', 
     'USER': 'paul', 
     'PASSWORD': 'm2aJup2fHYDdArGT', 
     'OPTIONS': { 
      'autocommit': True, 
     }, 
    } 
} 

# Internationalization 
# https://docs.djangoproject.com/en/1.7/topics/i18n/ 

LANGUAGE_CODE = 'de-de' 

TIME_ZONE = 'Europe/Berlin' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.7/howto/static-files/ 

STATIC_URL = '/static/' 
+0

데이터베이스 구성을 게시 할 수 있습니까? settings.py 파일에 있습니다 – levi

+0

아마도 당신의 설정에서 무언가 앞에'b'가 붙어 있습니까? ('b'blabla '). 그러면 [bytearray]가 생깁니다 (https://docs.python.org/3.1/library/stdtypes.html#bytes-methods) – RickyA

+0

settings.py를 추가했습니다. 나는 그것이 도움이되기를 바랍니다. 다른 모든 코드는 GitHub에 있습니다. 링크는 다음과 같습니다. https://github.com/pkreker/p_kreker –

답변

1

오늘이 오류가 발생했습니다. 나는 내 데이터베이스를 utf8_bin 데이터 정렬로 만들었는데, 데이터 정렬의 이유라고 생각합니다. utf8_general_ci으로 다시 만든 DB를 삭제하고 마이그레이션을 실행하여 정상적으로 작동했습니다.

+0

맞다. 나는 똑같은 어리석은 실수를했다. (당신의 대답에 감사드립니다 :) –

2

나는이 MySQL의 커넥터 - 파이썬에 버그가 될 가능성이 높습니다 생각 - 그것은 장고 1.7.4를 지원합니까? sqlite를 사용하여 코드를 실행하면 코드가 올바르게 작동합니다.

+0

네, 맞습니다. 나는 장고 개발자들과 이야기를 나누었고 그들은 같은 것을 말했다. 나는 mysql bugreport에서 버그를보고했다. 나는 버그를 고치고 싶다. 그러나 나는 파이썬에 매우 익숙하다. 그래서 버그를 고칠 때까지 기다려야 할 것이다. –

+0

나는 Django 핵심 개발자이기도하다. - 그들이 기꺼이 동의했다 :-) – spookylukey

1

버그 헤드 라인에서 "Django"를 지정하지 않았으므로 많은 Python 3 초보자가 여기에 올 것으로 예상됩니다. "bytearray"에 대한 해시 가능/불변의 카운터 파트는 "바이트"유형입니다.

>>> b1 = bytearray([1, 2, 3]) 
>>> s = set() 
>>> s.add(b1) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: unhashable type: 'bytearray' 
>>> b2 = bytes(b1) 
>>> b2 
b'\x01\x02\x03' 
>>> s.add(b2) 
>>> 
관련 문제