Introduction to the versions required to connect to the PostgreSQL database using Python

Source: Internet
Author: User

In the actual application process, connecting Python to the PostgreSQL database is a headache, because you need to download the relevant version when connecting Python to the PostgreSQL database, the following article describes how to solve the problem.

1. Install the PostgreSQL database. You can use version 8.4.2 to download the database.

2. In ipvs, run the Windows Installation version directly;

3. after the installation is complete, the Database Service should run automatically, you can run the pgadminIII graphic interface management tool in the "Start"> "program"> "postgresql" folder to manage the psycopg package used for database installation and python connection, (in windows, I used the compiled binary version psycopg 2.0.13forpython2.6)

After the database connection module is installed, you can use the test method described above to connect to the database through django.

You can create a new apps) and write a model.

The system has an agreement on the app: if you use the Django database layer model), You must create a django app. The model must be stored in apps. Therefore, to start building our model, we must create a new app.

Create a model in the newly created models. py. Each model is equivalent to a single database table, and each attribute is also a field in this table. The attribute name is the field name. Its type is CharField, which is equivalent to the field type of the database, such as varchar ).

In the process of connecting Python to the PostgreSQL database, use the following command to verify the validity of the model:

 
 
  1. python manage.py validate 

The validate command checks whether the syntax and logic of your model are correct. If everything is normal, you will see the 0 errors found message.

Run the following command to generate the create table statement:

 
 
  1. python manage.py syncdb 

After executing this command, the database is automatically generated. It checks the database based on the app set in INSTALLED_APPS. If the table does not exist, it creates it. Note that syncdb cannot synchronize model modifications to the database.

Nothing happens because you have not added a new model or a new app. The above is an introduction to some of the operations related to connecting python to the PostgreSQL database.

Related Article

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.