django module creates a data table using the synchronization method

A configuration database 100 OK

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'students',
'NAME': 'django_mall',
'USER':'root',
'PASSWORD':'',
'HOST':'127.0.0.1',
'PORT':'3306'
}
}

2 加载模块

= The INSTALLED_APPS [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles' ,
'debug_toolbar',
'mall.apps.MallConfig', # commodity module
'accounts.apps.AccountsConfig', # user account module
'system.apps.SystemConfig', # system module
'mine.apps.MineConfig', # individual modules
'weibo.apps.WeiboConfig',
'grade.apps.GradeConfig'

]

3 create a model database
constants.py

# System Module - Carousel FIG arranged
SLIDER_TYPE_INDEX =. 11
SLIDER_TYPES_CHOICES = (
(SLIDER_TYPE_INDEX, 'Home')
)


# System Module - news notifications
NEWS_TYPE_NEW =. 11
NEWS_TYPE_NOTICE = 12 is
NEWS_TYPES_CHOICES = (
(NEWS_TYPE_NEW, 'news'),
(NEWS_TYPE_NOTICE,' notifications ')
)

Models django.db Import from 

from utils Import Constants
# here Wallpaper the Create your Models.


class the Slider (models.Model):
"" "The system of FIG rotation" ""
name = models.CharField ( 'name', MAX_LENGTH = 32)
desc = models.CharField ( 'description', MAX_LENGTH = 100, null = True, blank = True)
type = models.SmallIntegerField ( 'presentation position',
choices = constants.SLIDER_TYPES_CHOICES,
default = constants.SLIDER_TYPE_INDEX)
IMG = models.ImageField ( ' picture ', upload_to =' Slider ')
Reorder = models.SmallIntegerField (' sort ', default = 0, = help_text ' the higher the number, the more forward ')
start_time = models.DateTimeField (' take effect starting time ', null = True ,blank=True)
end_time = models.DateTimeField ( 'commencement end time', null = True, blank = True)

TARGET_URL = models.CharField ( 'jump address', MAX_LENGTH = 255, null = True, blank = True)
is_valid models.BooleanField = ( 'delete', default = True)

created_at = models.DateTimeField ( 'creation time', auto_now_add = True)
updated_at = models.DateTimeField ( 'last modified', auto_now = True)

class Meta:
db_table = 'system_slider'
Ordering = [ '-reorder']


class News (models.Model):
"" "news and notice" ""
types models.SmallIntegerField = ( 'type', choices = constants.NEWS_TYPES_CHOICES,
default = constants.NEWS_TYPE_NEW)
title = Models.As CharField ( 'title', MAX_LENGTH = 255)
Content = models.TextField ( 'content')
reorder = models.SmallIntegerField ( 'sort', default = 0, = 'larger the number, the more forward' help_text)
START_TIME = models.DateTimeField ( 'time of commencement', null = True, blank = True)
END_TIME = Models. DateTimeField ( 'entry into force of the end of time', null = True, blank = True)
view_count = models.IntegerField ( 'Views', default = 0)

is_top = models.BooleanField ( 'whether top', default = False)

is_valid = Models. BooleanField ( 'delete', default = True)

created_at = models.DateTimeField ( 'creation time', auto_now_add = True)
updated_at = models.DateTimeField ( 'last modified', auto_now = True)

class Meta:
db_table = 'system_news'
= Ordering [ '-reorder']

. 4 sync data command table

python manage.py check

python manage.py makemigrations

python manage.py migrate

Successful synchronization

 

Guess you like

Origin www.cnblogs.com/ericblog1992/p/11496265.html