Django项目中如何建表?怎样导入数据?

http://django-chinese-docs.readthedocs.org/en/latest/topics/db/models.html

 

通常在项目中的models.py文件中建表的
This example model defines a Person, which has a first_name and last_name:
from django.db import models

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

first_name and last_name are fields of the model. Each field is specified as a class attribute, and each attribute maps to a database column.

The above Person model would create a database table like this:

CREATE TABLE myapp_person (
    "id" serial NOT NULL PRIMARY KEY,
    "first_name" varchar(30) NOT NULL,
    "last_name" varchar(30) NOT NULL);

posted @ 2015-04-08 11:11  Xander-Hang  阅读(396)  评论(0编辑  收藏  举报