python - Connect mysql to django -


i connect django (1.10) localhost (macos x) mysql database (mysql-server) located on distant server (ubuntu 14.04) instead of sqllite3.

i made changes in django' settings.py file :

databases = {     'default': {         'engine': 'django.db.backends.mysql',         'name': 'etat_civil',         'user': 'root',         'password': '*****',         'host': '172.**.**.58',         'port': '80',     } 

on distant server, installed mysql-server , juste created table.

and when run :

python manage.py migrate  

i error :

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>     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 

i need install thing in order connect django (python) mysql ? or have change :

'engine': 'django.db.backends.mysql', 

by

'engine': 'mysql-server', 

if run :

python3.5 manage.py migrate 

i :

macbook-pro-de-valentin:etat_civil valentinjungbluth$ python3.5 manage.py migrate traceback (most recent call last):   file "manage.py", line 8, in <module>     django.core.management import execute_from_command_line importerror: no module named 'django'  during handling of above exception, exception occurred:  traceback (most recent call last):   file "manage.py", line 14, in <module>     import django importerror: no module named 'django'  during handling of above exception, exception occurred:  traceback (most recent call last):   file "manage.py", line 17, in <module>     "couldn't import django. sure it's installed , " importerror: couldn't import django. sure it's installed , available on pythonpath environment variable? did forget activate virtual environment? 

thank :)

edit after steps :

nothing moment. followed advices , tutorial , none result moment : tutorial

you can find ans here database configuration

database configuration snippet link

configure django database settings:

now have project, need configure use database created.

open main django project settings file located within child project directory:

nano ~/myproject/myproject/settings.py 

towards bottom of file, see databases section looks this:

. . .  databases = {     'default': {         'engine': 'django.db.backends.sqlite3',         'name': os.path.join(base_dir, 'db.sqlite3'),     } }  . . . 

this configured use sqlite database. need change our mysql/mariadb database used instead.

first, change engine points mysql backend instead of sqlite3 backend. name, use name of database (myproject in our example). need add login credentials. need username, password, , host connect to. we'll add , leave blank port option default selected:

. . .  databases = {     'default': {         'engine': 'django.db.backends.mysql',         'name': 'myproject',         'user': 'myprojectuser',         'password': 'password',         'host': 'localhost',         'port': '',     } }  . . . 

when finished, save , close file.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -