Django系列3:Model的简单对接

Posted xidianzxm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django系列3:Model的简单对接相关的知识,希望对你有一定的参考价值。

1、models.py

from django.db import models

# Create your models here.
class Student(models.Model):
    s_name = models.CharField(max_length=16)
    s_age = models.IntegerField(default=1)

2、python manage makemigrations

(venv) MacBookPro:HelloDjango zhangxm$ python manage.py makemigrations
Migrations for 'Two':
  Two/migrations/0001_initial.py
    - Create model Student
(venv) MacBookPro:HelloDjango zhangxm$ 

技术图片

# Generated by Django 2.2.9 on 2020-01-22 02:28

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Student',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('s_name', models.CharField(max_length=16)),
                ('s_age', models.IntegerField(default=1)),
            ],
        ),
    ]

3、python manage.py migrate

(venv) MacBookPro:HelloDjango zhangxm$ python manage.py migrate
Operations to perform:
  Apply all migrations: Two, admin, auth, contenttypes, sessions
Running migrations:
  Applying Two.0001_initial... OK
(venv) MacBookPro:HelloDjango zhangxm$ 

技术图片

以上是关于Django系列3:Model的简单对接的主要内容,如果未能解决你的问题,请参考以下文章

千锋Django学习笔记

pbootcms对接微信扫码登录代码核心片段和步骤(前后端)

Django REST framework 基本组件

Django系列7:Model数据操作集合单个切片

AnjularJS系列3 —— 数据的双向绑定

第一章:模型层model layer -- Django从入门到精通系列教程