首先将account加入settings.py的INSTALLED_APPS中
如下
INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘account.apps.AccountConfig‘, ]
在accout/apps.py中进行相关设置
from __future__ import unicode_literals from django.apps import AppConfig class AccountConfig(AppConfig): name = ‘account‘
设计account/models.py
from __future__ import unicode_literals from django.db import models # Create your models here. class Customer(models.Model): Username = models.CharField(default=None, max_length=30) Nickname = models.CharField(default=None, max_length=30) Telephone = models.CharField(default=None, max_length=11) Email = models.EmailField Password = models.CharField(default=None, max_length=20) def __str__(self): return self.Nickname
数据库的创建和更新
如果设置默认数据库为MySQL的话, 首先数据库要存在,然后在settings.py中进行以下设置
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, ‘HOST‘: ‘127.0.0.1‘, #‘NAME‘: os.path.join(BASE_DIR, ‘ElecMalldb‘), ‘NAME‘: ‘ElecMalldb‘, ‘USER‘: ‘root‘, ‘PASSWORD‘: ‘ss175625‘, ‘PORT‘: 3306, } }
运行以下命令进行数据库同步
python manage.py makemigrations python manage.py migrate
时间: 2024-10-22 09:19:09