私のlocalhost(MacOS X)からDjango(1.10)を、sqlLite3の代わりに遠いサーバー(Ubuntu 14.04)にあるMysqlデータベース(Mysql-server)に接続します。私はDjangoの「settings.pyファイルにいくつかの変更を行わdjangoにmysqlを接続します
:遠くのサーバで
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Etat_Civil',
'USER': 'root',
'PASSWORD': '*****',
'HOST': '172.**.**.58',
'PORT': '80',
}
を、私はmysql-server
をインストールし、私はテーブルを作成しジュスト。
そして、私は実行すると:私はジャンゴ(パイソン)のMySQLに接続するために別のものをインストールする必要が
MacBook-Pro-de-Valentin:Etat_Civil valentinjungbluth$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Library/Python/2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Library/Python/2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/Library/Python/2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
:
python manage.py migrate
が、私はこのエラーを取得しますか?
python3.5 manage.py migrate
私が手::
'ENGINE': 'django.db.backends.mysql',
私が実行している場合は
'ENGINE': 'mysql-server',
によって:または私は変更する必要が
MacBook-Pro-de-Valentin:Etat_Civil valentinjungbluth$ python3.5 manage.py migrate
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
助けてくれてありがとう:)いくつかのステップAFTER
EDIT:
何も一瞬。最後の行はDid you forget to activate a virtual environment?
を述べ
Configure the Django Database Settings:
Now that we have a project, we need to configure it to use the database we created.
Open the main Django project settings file located within the child project directory:
nano ~/myproject/myproject/settings.py
Towards the bottom of the file, you will see a DATABASES section that looks like this:
. . . DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } . . .
This is currently configured to use SQLite as a database. We need to change this so that our MySQL/MariaDB database is used instead.
First, change the engine so that it points to the mysql backend instead of the sqlite3 backend. For the NAME, use the name of your database (myproject in our example). We also need to add login credentials. We need the username, password, and host to connect to. We'll add and leave blank the port option so that the default is selected:
. . . DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'myproject', 'USER': 'myprojectuser', 'PASSWORD': 'password', 'HOST': 'localhost', 'PORT': '', } } . . .
When you are finished, save and close the file.
アクティブにするのを忘れた仮想env設定がありますか?また、要件ファイルがある場合は、必ず実行してください。 – karthikr
ほんの少しの質問:1)あなたはmysqlサーバー上のポート80について確かですか?デフォルトは80ではありません2)過去に私はMySQL-pythonをインストールしなければなりませんでしたが、それがインストールされている場合は 'pip freeze'で確認できますか? – Aditya
@karthikr私はvirtual.envを忘れてしまった。だから私はチュートリアルに従っていますが、これは起動しましたが、私はいつもこのエラーを受け取ります。 'MySQLdbモジュールの読み込み中にエラーが発生しました:' mysqldb 'というモジュールがありません。 – Deadpool