Django has model generation SQL and existing reverse table generation model

Source: Internet
Author: User

There are already models generated SQL statements

Syntax python manage.py sqlall app_name # app_name, has been imported in Settings,

Such as:

Installed_apps = (
' Django.contrib.admin ',
' Django.contrib.auth ',
' Django.contrib.contenttypes ',
' Django.contrib.sessions ',
' Django.contrib.messages ',
' Django.contrib.staticfiles ',
"Apps.libs.models.weixin",
)

Python manage.py sqlall Weixin

Wei-2: tbkw (develop) admin$ python manage.py sqlall weixin{'Db_jx_master_host':'mysql.rds.aliyuncs.com','Db_jx_port':'3306','Db_jx_user':'TB','Db_jx_password':'TB'}begin; CREATE TABLE ' wechat_config ' (' id ' integer auto_increment NOT null PRIMARY KEY, ' user_id ' integer NOT NULL, ' app _id ' varchar (50) not NULL, ' app_secret ' varchar (50) not NULL, ' app_token ' varchar (100) not NULL, ' access_token ' varchar (200) not NULL, ' access_token_expire_in ' Integer, ' add_time ' DateTime (6) not NULL); CREATE TABLE ' Wechat_menu ' (' id ' integer auto_increment NOT null PRIMARY KEY, ' wechat_id ' integer NOT null, ' Men U_name ' varchar (50) not NULL, ' menu_type ' varchar (20) not NULL, ' menu_key ' varchar (50) not NULL, ' menu_value ' varchar (50Not null, ' Is_button ' integer NOT NULL, ' level_id ' integer NOT NULL, ' parent_id ' integer, ' sequence ' int Eger not NULL);    CREATE TABLE ' wechat_autoreply ' (' id ' integer auto_increment NOT null PRIMARY KEY, ' wechat_id ' integer NOT NULL, ' Replay_type ' integer not NULL, ' keyword ' varchar (100) not NULL, ' is_welcome ' integer NOT NULL, ' Unmatch ' integer NOT null, ' text ' varchar (1000) Not NULL, ' media ' varchar (100) not NULL, ' Add_time ' DateTime (6) not NULL);    CREATE TABLE ' wechat_material ' (' id ' integer auto_increment NOT null PRIMARY KEY, ' wechat_id ' integer NOT NULL, ' title ' varchar (100) not NULL, ' author ' varchar (100Not null, ' content ' longtext not null, ' source_url ' varchar (100) not NULL, ' cover ' varchar (100) not NULL, ' cover_show ' integer NOT NULL, ' summary ' varchar (1000) not NULL, ' Add_time ' DateTime (6) not NULL);    CREATE TABLE ' Wechat_msg_push ' (' id ' integer auto_increment NOT null PRIMARY KEY, ' wechat_id ' integer NOT NULL, ' Is_push ' integer NOT NULL, ' template_id ' integer NOT null, ' title ' varchar (100) not NULL, ' content ' longtext not null, ' Add_time ' DateTime (6) not NULL);

$ python manage.py makemigrations Weixin

There is an existing table reverse generation models

Syntax python manage.py inspectdb

Wei-2: tbkw (develop) admin$ python manage.py inspectdb{'Db_jx_master_host':'mysql.rds.aliyuncs.com','Db_jx_port':'3306','Db_jx_user':' TB','Db_jx_password':' TB'}#This is an auto-generated Django model module.#You'll have the following manually to the#* Rearrange models ' order#* Make sure each model have one field with Primary_key=true#* Remove ' managed = False ' lines if you wish to allow Django to create, modify, and delete the table#feel free to rename the models, but don ' t rename db_table values or field names.##Also Note:you ' ll has to insert the output of ' django-admin Sqlcustom [App_label] '#into your database. from __future__ Importunicode_literals fromDjango.dbImportModelsclassAuthuser (models. Model): Username= Models. Charfield (Unique=true, max_length=30) first_name= Models. Charfield (max_length=30) last_name= Models. Charfield (max_length=30) Email= Models. Charfield (max_length=75) Password= Models. Charfield (max_length=128) Is_staff=models. Integerfield () is_active=models. Integerfield () Is_superuser=models. Integerfield () Last_login= Models. Datetimefield (Blank=true, null=True) date_joined=models. Datetimefield () Logins=models. Integerfield () Phone= Models. Charfield (max_length=11, Blank=true, null=True) QQ= Models. Charfield (max_length=13, Blank=true, null=True)classmeta:managed=False db_table='Auth_User'classBankAccount (models. Model): Username= Models. Charfield (max_length=50) Amount= Models. Decimalfield (max_digits=11, decimal_places=2) Balance= Models. Decimalfield (max_digits=8, decimal_places=2) Add_date=models. Integerfield ()classmeta:managed=False db_table='Bank_account'

.

Django has model generation SQL and existing reverse table generation model

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.