One, the Django self-contained ORM can define the relationship between tables and tables, and now compare the implementation of the database-side between the various relationships
1. ForeignKey Relationship
from Import Models # Create your models here. class User (models. Model): name=models. Charfield (max_length=30) phonenumber=models. Bigintegerfield ()class Blog (models. Model): user=models. ForeignKey (User) blogname=models. Charfield (max_length=16) content=models. TextField ()#
CREATE TABLE' Sitea_user ' (' ID ')int( One) not NULLauto_increment, ' name 'varchar( -) not NULL, ' PhoneNumber 'bigint( -) not NULL, PRIMARY KEY(' id ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;CREATE TABLE' Sitea_blog ' (' ID ')int( One) not NULLauto_increment, ' Blogname 'varchar( -) not NULL, ' content ' Longtext not NULL, `user_id`int( One) not NULL, PRIMARY KEY(' id '),KEY' Sitea_blog_user_id_2c1e69b4_fk_sitea_user_id ' ('user_id`), CONSTRAINT' sitea_blog_user_id_2c1e69b4_fk_sitea_user_id 'FOREIGN KEY(`user_id`)REFERENCES' Sitea_user ' (' ID ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;
---
Dango models and database----relation ship