There was a problem testing Django today, and I was badly burned.
D:\pythonCode\django\mysite>django-admin.py startproject mysite
And then I’m going to create my APP, which I’m going to call MB
python manage.py startapp mb
The directory structure is as follows:
D:.
│ manage.py
│
├─mb
│ admin.py
│ models.py
│ models.pyc
│ tests.py
│ views.py
│ __init__.py
│ __init__.pyc
│
└─mysite
settings.py
settings.pyc
urls.py
wsgi.py
__init__.py
__init__.pyc
For testing, I created a very simple model
Modify the MB – & gt; Models.py, with only one field
from django.db import models
# Create your models here.
class Test(models.Model):
testField = models.TextField()
Modify the mysite – & gt; settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mysite.mb',
)
Note: This is where I want the database to be set to
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'D:\\test.db',
}
}
When performing database tests
manage.py sql mb
Error message:
ImportError: No module named mb
Well, I set it in Settings.py, why don’t I have this model?
I don’t know, Baidu, will mysite-> Settings. Py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mb',
)
This time, there it is
BEGIN;
CREATE TABLE "mb_test" (
"id" integer NOT NULL PRIMARY KEY,
"testField" text NOT NULL
)
;
COMMIT;
It looks like a success, but why?For explanation.