Dango models and database----relation ship

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.