2016-09-08 14 views
0

このコードは、他の人のローカルコンピュータでも動作します。しかし、私は働いていません。同僚はデータベースを作成する必要があることを示しました。 mysqlを使用する前に、私はsqliteを使用していましたが、これはこれを必要としませんでした。Djangoデータベースを作成する

私はこのRUNSERVERのpython manage.pyを実行して、私が得るものです:

XX-MacBook-Pro:xx xx$ python manage.py runserver 
Performing system checks... 

Unhandled exception in thread started by <function wrapper at 0x104ebb668> 
Traceback (most recent call last): 
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper 
    fn(*args, **kwargs) 
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run 
    self.check(display_num_errors=True) 
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 426, in check 
    include_deployment_checks=include_deployment_checks, 
File "/Library/Python/2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks 
    new_errors = check(app_configs=app_configs) 
File "/Library/Python/2.7/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models 
    errors.extend(model.check(**kwargs)) 
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 1170, in check 
errors.extend(cls._check_fields(**kwargs)) 
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 1247, in _check_fields 
    errors.extend(field.check(**kwargs)) 
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 925, in check 
    errors = super(AutoField, self).check(**kwargs) 
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 208, in check 
    errors.extend(self._check_backend_specific_checks(**kwargs)) 
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 317, in _check_backend_specific_checks 
    return connections[db].validation.check_field(self, **kwargs) 
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/validation.py", line 18, in check_field 
    field_type = field.db_type(connection) 
File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 625, in db_type 
    return connection.data_types[self.get_internal_type()] % data 
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 36, in __getattr__ 
    return getattr(connections[DEFAULT_DB_ALIAS], item) 
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 33, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 184, in data_types 
    if self.features.supports_microsecond_precision: 
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 33, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/features.py", line 53, in supports_microsecond_precision 
    return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5) 
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 33, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 359, in mysql_version 
    with self.temporary_connection(): 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__ 
    return self.gen.next() 
File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 564, in temporary_connection 
    cursor = self.cursor() 
File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 233, in cursor 
    cursor = self.make_cursor(self._cursor()) 
File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor 
    self.ensure_connection() 
File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection 
    self.connect() 
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 95, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection 
    self.connect() 
File "/Library/Python/2.7/site-packages/django/db/backends/base/base.py", line 171, in connect 
    self.connection = self.get_new_connection(conn_params) 
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 264, in get_new_connection 
    conn = Database.connect(**conn_params) 
File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect 
    return Connection(*args, **kwargs) 
File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 193, in __init__ 
    super(Connection, self).__init__(*args, **kwargs2) 
django.db.utils.OperationalError: (1049, "Unknown database 'testdb'") 

私の設定ファイルには、これを持っている:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

...

DATABASES = { 
    'default': { 
    'ENGINE': 'django.db.backends.mysql', 
    'NAME': 'testdb', 
    'USER': ‘xx’, 
    'PASSWORD': ‘xx’, 
    'HOST': 'localhost' 
    } 
} 

私は」ユーザー、パスワードをテストし、彼らが働いていることを知っている。私のMySQLは完全に機能しています。

私はDATABASES「NAME」を削除した場合、私は得る:

django.db.utils.OperationalError: (1046, 'No database selected') 

答えて

0

は、おそらくあなたは、mysqlのシェルに行くことによって、ユーザ名とパスワードをテストしています。だから、同じことをもう一度やることができます。そこからはCREATE DATABASE testdbを実行します。

+0

私はPythonのmanage.pyのshell' '経由シェルに行き、私が手testdb' CREATE DATABASEを'入力: ' はファイル ""、行1 がTESTDB ^ にSyntaxErrorデータベースを作成TESTDBデータベースを作成>>> :無効な構文 >>> ' – Lefty

+0

このコマンドは、PythonシェルではなくSQLシェルに入力する必要があります。 'python manage.py shell'の代わりに' python manage.py dbshel​​l'を実行してください。 –

+0

それはそれでした。助けてくれてありがとう、ジョンゴードン! – Lefty

関連する問題