# article 
class Article(models.Model):
title = models.CharField(' title ', max_length=70)
excerpt = models.TextField(' Abstract ', max_length=200, blank=True)
category = models.ForeignKey(Category, on_delete=models.DO_NOTHING, verbose_name=' classification ', blank=True, null=True)
# Using foreign key to associate classification table with classification is one to many relationship
tags = models.ManyToManyField(Tag, verbose_name=' label ', blank=True)
# Using foreign key to associate label table with label is many to many relationship
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=' Operator ')
views = models.PositiveIntegerField(' Reading volume ', default=0)
tui = models.ForeignKey(Tui, on_delete=models.DO_NOTHING, verbose_name=' Recommended bit ', blank=True, null=True)
created_time = models.DateTimeField(' Release time ', auto_now_add=True)
modified_time = models.DateTimeField(' Modification time ', auto_now=True) class Meta:
verbose_name = ' Homework list '
verbose_name_plural = ' Homework list ' Actually generated mysql surface

among article surface

mysql Of DDL

CREATE TABLE `les_article` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(70) NOT NULL,
`excerpt` longtext NOT NULL,
`views` int(10) unsigned NOT NULL,
`created_time` datetime(6) NOT NULL,
`modified_time` datetime(6) NOT NULL,
`category_id` int(11) DEFAULT NULL,
`tui_id` int(11) DEFAULT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `les_article_category_id_b89e56fb_fk_les_category_id` (`category_id`),
KEY `les_article_tui_id_dfb5096f_fk_les_tui_id` (`tui_id`),
KEY `les_article_user_id_9190afe0_fk_auth_user_id` (`user_id`),
CONSTRAINT `les_article_category_id_b89e56fb_fk_les_category_id` FOREIGN KEY (`category_id`) REFERENCES `les_category` (`id`),
CONSTRAINT `les_article_tui_id_dfb5096f_fk_les_tui_id` FOREIGN KEY (`tui_id`) REFERENCES `les_tui` (`id`),
CONSTRAINT `les_article_user_id_9190afe0_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8

among article_tags surface

mysql Of DDL

CREATE TABLE `les_article_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`article_id` int(11) NOT NULL,
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `les_article_tags_article_id_tag_id_ebc98ef0_uniq` (`article_id`,`tag_id`),
KEY `les_article_tags_tag_id_190aec01_fk_les_tag_id` (`tag_id`),
CONSTRAINT `les_article_tags_article_id_d83efe78_fk_les_article_id` FOREIGN KEY (`article_id`) REFERENCES `les_article` (`id`),
CONSTRAINT `les_article_tags_tag_id_190aec01_fk_les_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `les_tag` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8

--------------------------------------------------------

class Category(models.Model):
name = models.CharField(' Business classification ', max_length=100)
index = models.IntegerField(default=999, verbose_name=' Sorting and sorting ') class Meta:
verbose_name = ' Business classification '
verbose_name_plural = verbose_name def __str__(self):
return self.name

-------------------------------------------------------------------------------

class Tag(models.Model):
name = models.CharField(' Job label ', max_length=100) class Meta:
verbose_name = ' Job label '
verbose_name_plural = verbose_name def __str__(self):
return self.name

----------------------------------------------------

# Recommended bit 
class Tui(models.Model):
name = models.CharField(' Recommended bit ', max_length=100) class Meta:
verbose_name = ' Recommended bit '
verbose_name_plural = verbose_name def __str__(self):
return self.name

--------------------------------------------------------------

class Link(models.Model):
name = models.CharField(' Link name ', max_length=20)
linkurl = models.URLField(' website ', max_length=100) def __str__(self):
return self.name class Meta:
verbose_name = ' link '
verbose_name_plural = ' link '



django model Design and actual database table comparison of more related articles

  1. Hibernate from model Class automatically synchronizes the database table structure

    There is a problem in the development , Every time you add a table structure to the test database , Local pull Next, the latest code causes the startup to report an error , Search the Internet for quick solutions ---->hibernate In the configuration properties ,hibernate.hbm2ddl.aut ...

  2. Java Second kill simple design 2 : Database tables and Dao Floor design

    Java Second kill simple design 2 : Database table Dao Floor design In the last article, I built springboot Project environment and design database tables  https://www.cnblogs.com/taiguyiba/p/9791431.html ...

  3. django( 8、 ... and ) One to many of the database tables , Many-to-many table - Additions and deletions

    Single table operation Adding table records Mode one : Book() b=Book(name="python Basics ",price=99,author="yuan",pub_date=& ...

  4. django( 7、 ... and ) Single table of database table - Additions and deletions QuerySet, Double underline

    https://www.cnblogs.com/haiyan123/p/7738435.html https://www.cnblogs.com/yuanchenqi/articles/6083427 ...

  5. Database table structure comparison synchronization mysqldiff

    The database table structure of the development server has been modified , Or too many changes , To synchronize with the online database structure , have access to mysqldiff Tools to patch online databases . mysqldiff Windows Download address :http://dev.my ...

  6. python Django And Model ORM inspectdb( Reverse generation of database tables )

    In the previous article we said ,mybatis-generator Reverse code generation . Here we begin to talk about how to django Reverse generation in mysql model Code . We're showing django ORM Before reverse generation , Let's talk about how to ...

  7. Django On the basis of models Generate database table __init__() missing 1 required positional argument: 'on_delete'

    from django.db import models # Create your models here. class Category(models.Model): caption = mode ...

  8. Django On the basis of models Error generating database table

    Error message : E:\Python\s6day103>python manage.py makemigrations Traceback (most recent call last): File ...

  9. Django On the basis of models Error generating database table : __init__() missing 1 required positional argument: 'on_delete'

    reason : stay django2.0 after , When defining foreign keys and one-to-one relationships, you need to add on_delete Options , This parameter is used to avoid data inconsistency between two tables , Otherwise, it will report a mistake :TypeError: __init__() missing ...

Random recommendation

  1. Carton stacking bzoj 2253

    Carton stacking (1s 128MB) box [ Problem description ] P A factory is a factory that produces cartons . The carton production line input three parameters manually n, p, a after , The length of three sides is (a mod P, a^2 mod p ...

  2. Record once MongoDB3.0.6 edition wiredtiger And MMAPv1 Compare the write time of the engine

    One .MongoDB3.0.x Version features of ( be relative to MongoDB2.6 And the following ): Added wiredtiger engine : Open source storage engine : Support multi-core CPU. Make the most of memory / Chip level cache ( notes :10 month 14 Just released on May ...

  3. OD Use the tutorial 9

    Run the program first and open about, Found that this is an unregistered software, you need to register before you can use the tools inside , So just sign up , Jump out of a prompt that the registered email is illegal , So we can take this as a breakthrough to crack this program Use the prompt statement as a keyword to find out ...

  4. View the native IP Address method :

    View the native IP Address method : about XP System : Method 1 : If there is a small computer connected locally in the tray area of the system in the lower right corner , Double click on the small computer → Support , You can see this machine IP Address . It's the same with wireless connections . Method 2 : Start → function cmd /k ipconfig,IP ...

  5. XSS CSRF

    XSS CSRF XSS Reference resources https://zh.wikipedia.org/wiki/%E8%B7%A8%E7%B6%B2%E7%AB%99%E6%8C%87%E4%BB%A4%E7%A2%BC ...

  6. C# - Database access pictures

    1. Create data table CREATE TABLE Tb_pic ( ID int primary key identity(1, 1) not null, PictureBox varchar(max) ) ...

  7. [UWP Xiao Bai's diary -14] Regular expressions

    matching 2 Bit floating point :  ^(([1-9]+[0-9]*\.{1}[0-9]{1,2})|([0]\.{1}[1-9]+[0-9]{1,2})|([0]\.\d{1,2})|([1-9][0-9]{1,2} ...

  8. Java Basics —— Reflection reflect

    What is reflection (1)Java The reflection mechanism is in the running state , For any class , Can know all the properties and methods of this class : For any object , Can call any of its methods and properties : The function of dynamically obtaining information and dynamically calling methods of objects is called ...

  9. Talking about SSH frame

    When learning or coming into contact with a new concept , We should use our search engine in our mind , Take a whole body and think about it , What are the similarities or differences between this knowledge and what I have been exposed to before , Look at the new knowledge and concepts from this perspective , After comparing old knowledge with new knowledge, I ...

  10. Mybatis Source learning series

    Preface Long ago , We learned Java, From a console Hello world . Start , We're in the object-oriented world . And then by learning SQL Language , You can write SQL Statement to store the database data under the hard disk , show . after ...