Python27+django Creating an App

Source: Internet
Author: User

Python manage.py Startapp Polls create an app called polls

Edit File polls/models.py:

1from django.db Import Models2class Poll (models. Model): 3 question = models. Charfield (max_length=200) 4 pub_date = models. Datetimefield (' date published ')

Edit the file settings.py again, modify the settings Installed_apps contain the string ' polls '. The modified configuration is as follows:

Installed_apps = (' Django.contrib.auth ', ' django.contrib.contenttypes ', ' django.contrib.sessions ', ' Django.contrib.sites ', ' polls ')


Now Django knows to include the polls application.

In Django, there is a table that records all the model metadata in the project, which is ContentType. A record in the table corresponds to an existing model, so we can find any record in any model by using the ID of a metadata table and an ID in a specific data table. The module is included in the Django default module

After django1.9, use migrate instead of SYSCDB

Runpython manage.py migrate来为数据库中每个应用建立一个数据库表。 

At first the error has been:

Runtimeerror:model class Django.contrib.auth.models.Permission doesn ' t declare an explicit App_label and isn ' t in an APPL Ication
In Installed_apps.

I have commented out the modules in the Django settings file, and the corresponding location has not changed, so the comment is re-run, over the

You can run the following command to check for traces:

    • Python manage.py Validate-check the model for structural errors.
    • Python manage.py sqlcustom Polls--outputs all custom SQL statements defined for the application (such as table modifications and constraints).
    • Python manage.py sqlclear Polls-outputs the necessary drop TABLE statements in this application, based on existing tables.
    • Python manage.py sqlindexes Polls--output This app CREATE INDEX statement.
    • Python manage.py sqlall Polls-the combination of SQL statements generated by the Sql,sqlcustom and Sqlindexes commands.

Python manage.py Migrate the main role is to generate the corresponding database to be used, the corresponding models need to be set in Settings, if changed, only need to use manage.py makemigrations command to commit the changes, You can then run Python manage.py migrate to update the database.

After the update is complete, you can see the table in the database, if you do not see, you can use the API way to verify, see the next article

Python27+django Creating an App

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.