-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',
}
}
10
  • 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? ) Commented Oct 7, 2015 at 17:56
  • we need more of your project structure, not just coding. Do you have a myApp folder? Commented Oct 7, 2015 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 Commented Oct 7, 2015 at 18:02
  • Please, show INSTALLED_APPS settings code Commented Oct 7, 2015 at 18:03
  • also syncdb was depreciated since 1.7, what is your version? Commented Oct 7, 2015 at 18:07

6 Answers 6

3
+25

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

4 Comments

@Farshid This comment needs more details! Did pip finished successfully? Maybe you need pip3 if you have two different versions of Python installed.
I say again : " I use python 3.5.0".
@Farshid Tell me at least whether pip installed the package successfully or failed to execute.
Yes, I can with it install packages!
-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

3 Comments

@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?
@Farshid did you substitute app_name for myApp like so: python manage.py startapp myApp ?
@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.
-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.

3 Comments

missing trailing comma
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.
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.
-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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.