-9

I am newbie in python. when I run this code python manage.py syncdb in cmd I get this error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 303, in execute
    settings.INSTALLED_APPS
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
    self._setup(name)
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\conf\__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\conf\__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "C:\Users\Farshid\Desktop\Trying\Ecom\coding\coding\settings.py", line 18, in <module>
    from myApp.models import *
ImportError: No module named 'myApp
   raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'

I googled but I couldn't catch good solution for it, and now how can I handle it? I use latest version of django last version of mysql community server-win64 and my python version is 3.5.0.

My project structure:

-coding
--coding
---__init__.py
---settings.py
---urls.py
---wsgi.py

--manage.py

INSTALLED_APPS

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

Edit: When I create new project and use slite3, don't get this error! and this is setting.py database section codes:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'coding',
    'USER': 'root',
    'PASSWORD': 'root',
    'HOST': 'localhost',
    'PORT':'3306',
}
}
Farshid Shekari
  • 2,391
  • 4
  • 27
  • 47
  • 1
    Can you add the structure of your project? What directories you made an where are `manage.py` and `myApp` in there. Also, what other files you have in the `myApp` directory (do you have a `__init__.py`? ) – spectras Oct 07 '15 at 17:56
  • we need more of your project structure, not just `coding`. Do you have a `myApp` folder? – Jared Hooper Oct 07 '15 at 18:02
  • 2
    So you have created a project, but there is no app in it yet. Go ahead a create one (`manage.py startapp myApp`) :) Checkout the [tutorial](https://docs.djangoproject.com/en/1.8/intro/tutorial01/) – spectras Oct 07 '15 at 18:02
  • Please, show INSTALLED_APPS settings code – Paulo Pessoa Oct 07 '15 at 18:03
  • also `syncdb` was depreciated since 1.7, what is your version? – Deja Vu Oct 07 '15 at 18:07
  • How i can get syncdb version? – Farshid Shekari Oct 07 '15 at 18:13
  • try `python manage.py makemigrations` and then `python manage.py migrate` if you are using 1.7+ – Deja Vu Oct 07 '15 at 18:28
  • To get your Django version, run `python manage.py --version`. If you are new to Django, make sure you are using the latest release, currently 1.8.5. You should use migrations instead of syncdb. If you work through the tutorial, it explains how to use migrations. – Alasdair Oct 07 '15 at 18:31
  • I run any instruction give me above error! – Farshid Shekari Oct 07 '15 at 18:40
  • Why do you import any models in your settings file? It won’t even run after you create the `myApp` app, as settings are initialised before (almost) everything else. – GergelyPolonkai Oct 09 '15 at 21:49

6 Answers6

3

With the information you have provided, I see two issues. First is the absence of a module "myApp" and then the mysql improperly configured error.

Let us take it this way,

1.python manage.py startapp myApp 2.In your settings, add the app thus: INSTALLED_APPS = (

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myApp',

)

3.pip install mysql-python to install mysql because it seems like you are missing that.

4.your db settings look ok which is why step 3 is important.

  1. Then python manage.py makemigrations myApp

  2. python manage.py migrate

7.Run your server and let's see what you've got

Edit: This should also help with the mysql error django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

Community
  • 1
  • 1
pycod333
  • 764
  • 2
  • 7
  • 16
1

From an older answer of mine:

If you're using python3, I found that the best option is use pymysql importing it in the settings file like so

import pymysql
pymysql.install_as_MySQLdb()

with django.db.backends.mysql set as the ENGINE.

mccc
  • 2,354
  • 1
  • 20
  • 22
0

Have you tried pip install mysqldb ? There is a special Python package to connect to MySQL server, which seems to be missing on your system.

Tigran Saluev
  • 3,351
  • 2
  • 26
  • 40
-1

You have no 'myApp' application in the INSTALLED_APPS setting.

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myApp'

Of course, app should be already in your project (created, cloned, copied or whatever) in order to be accessible.

chem1st
  • 1,624
  • 1
  • 16
  • 22
  • missing trailing comma – Deja Vu Oct 07 '15 at 18:20
  • 1
    Do you have this app (folder with `__init__.py` inside) in you project at least? @Deja Vu you do not need trailing comma after the last one. – chem1st Oct 07 '15 at 18:31
  • Comment out the 18th line of your settings.py (there you try to import all models from not existing yet app "myApp"). Create app then and add it to your installed apps. After that return your models import back. – chem1st Oct 07 '15 at 18:41
-1

From your project structure:

-coding
--coding
---__init__.py
---settings.py
---urls.py
---wsgi.py

--manage.py

It doesn't seem like you have any apps in your project.

To create an app type:

python manage.py startapp app_name

and replace app_name with the name of your app, myApp in your case.

After that you need to include the app in your INSTALLED_APPS in the settings.py file.

Further info: https://docs.djangoproject.com/en/1.8/intro/tutorial01/#creating-models

Fabio
  • 3,015
  • 2
  • 29
  • 49
  • @Farshid what error? Did you run the command I described? (`python manage.py startapp app_name`) Were you in the root folder of your project? – Fabio Oct 07 '15 at 18:59
  • @Farshid did you substitute app_name for myApp like so: `python manage.py startapp myApp` ? – Fabio Oct 07 '15 at 19:03
  • 1
    @Farshid if you still have "myApp" in INSTALLED_APPS and you try to run `startapp myApp`, it will throw the error. Make sure "myApp" isn't in INSTALLED_APPS until AFTER you have created the app. – Ben Oct 07 '15 at 19:16
-1

I don't know how to strike trough so i removed previous answer.

Update:

The simple answer is that Your 'myApp' is not seen by your python interpreter, ex. due to path mismatch. Add myApp to INSTALLED_APPS like pycod333 advised, and give us feedback (answer his question).

Abc Xyz
  • 1,184
  • 12
  • 13