Django Addendum (i)

Source: Internet
Author: User

Link MySQL Database

To modify a configuration file in a project:

DATABASES = {    'default': {        #' ENGINE ': ' Django.db.backends.sqlite3 ',        #' NAME ': Os.path.join (Base_dir, ' db.sqlite3 '),        'ENGINE':'Django.db.backends.mysql',        'NAME':'llll',#所MySQL database name of the application        'USER':'Root',#MySQL user name        'PASSWORD':'1232222',#mysql Password        'HOST':'127.0.0.1',#MySQL Address        'PORT':'3306'   #the port number of the MySQL database    }}

Name is the name of the database that the database must have been created before MySQL is connected.
User and PASSWORD are the username and password of the database respectively.
Once setup is complete, we need to activate our MySQL before starting our Django project.
Then, start the project, will error: no module named MySQLdb.
This is because Django defaults to the driver you are importing is MYSQLDB, but MySQLdb is a big problem for py3, so the driver we need is pymysql.
So, we just need to find the project name file under the __init__, which is written in:

Import pymysqlpymysql.install_as_mysqldb ()

Problem Solving!

Linux operating system view database address and port number:

' PORT ';

If the following error occurs, modify the user password in the database before executing makemigrations

 for ' Root '@'localhost'(using Password:yes)

Modify the database user password

' User name '@'localhost' = PASSWORD (' new password ');

Just a second link.

Model Field
classCustomer (models. Model):" "Customer Information Form" "name= Models. Charfield (max_length=32, Blank=true, null=true,verbose_name="name")    #blank null pair appears blank if NULL is present or the Django submission form does not pass the prompt input box to be emptyQQ = models. Charfield (max_length=64, unique=true,verbose_name="QQ")    #unique Setting this field only data cannot be repeated verbose_name settings in the Django Admin display in Chinesesource_choices= (0,'about the transfer'),                      (1,'QQ Group'),                      (2,'official website'),                      (3,'Baidu Promotion'),                      (4,'51CTO'),                      (5,'know'),                      (6,'Market Promotion') ) Source= Models. Smallintegerfield (choices=source_choices,verbose_name="Customer Source")    #choices= tuples can only insert the first data in a tuple within a tupleReferral_from= Models. Charfield (verbose_name="Introducing QQ", max_length=64, Blank=true, null=True) Consult_course= Models. ForeignKey ("Course", verbose_name="Consulting Courses") Content= Models. TextField (verbose_name="Inquiry Details") Tags= Models. Manytomanyfield ("Tag", Blank=true, Null=true,verbose_name="label") Consultant= Models. ForeignKey ("UserProfile", verbose_name="Sales Consultant") Memo= Models. TextField (Blank=true, null=true,verbose_name="Notes") Date= Models. Datetimefield (auto_now_add=true,verbose_name="Date")    #Auto_now_add automatically add current time when inserting data    def __str__(self):returnSELF.QQclassmeta:verbose_name_plural="Customer Information Form"        #The Chinese name of the table in Django AdminUnique_together= ('QQ','name')        ## federated unique QQ field and Name field

Django Addendum (i)

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.