Django创建数据库表格

记录配置              base:api名称
1、将settings.py中的DATABASES修改为可用的数据库配置
2、创建数据库
mysql中创建库
mysql -uroot -pXXX

CREATE DATABASE EasyTest ;
3、models.py里面创建数据库模型
from django.db import models
# Create your models here.
class Environment(models.Model):
    env_id = models.AutoField(primary_key=True, null=False)
    env_name = models.CharField(max_length=50)
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    description = models.CharField(max_length=100)
    url = models.CharField(max_length=100)
    private_key = models.CharField(max_length=50)

    def __str__(self):
        return self.env_name
4、settings.py中在INSTALLED_APPS将application添加
INSTALLED_APPS = [
    django.contrib.admin,
    django.contrib.auth,
    django.contrib.contenttypes,
    django.contrib.sessions,
    django.contrib.messages,
    django.contrib.staticfiles,
    base,
]

5、命令行运行,创建表格 

python3 manage.py migrate

python3 manage.py makemigrations base

python3 manage.py migrate base

 

6、启动程序

进入EasyTest目录执行:
python manage.py runserver 127.0.0.1:1314

 

Django创建数据库表格

上一篇:mysql变量


下一篇:mysql: navicat for mysql 执行快捷键