Django uses the model to create a field in the database tables used

Django model layer by not create the database, but you can create a database table, the following are parameter fields and table fields of table creation.

First, the field

1, models.AutoField auto-increment = int (11)
  , if not, generates a default name for the id column, if the custom to display an auto-increment, the column will be disposed
opposite a primary key primary_key = True.
2, models.CharField string field
   must max_length parameters
3, models.BooleanField boolean = tinyint (1)
   can not be empty, Blank = True
. 4, comma separated digital models.ComaSeparatedIntegerField = varchar
   inheritance CharField, parameters must max_lenght
5, models.DateField date type date
   for the parameters, auto_now = True then each update will update this time; auto_now_add is only the first record
was built to add, update after no change.
6, models.DateTimeField date datetime type
   with parameters DateField
7, models.Decimal = decimal decimal type
   must be specified bit integer and decimal max_digits decimal_places
. 8, models.EmailField string type (regular expressions mailbox) = varchar
   string regular expression
9, models.FloatField Double float type =
10, models.IntegerField shaping
11, models.BigIntegerField long integer
  integer_field_ranges = {
    'SmallIntegerField': (- 32768,32767),
    'IntegerField': (- 2147483648,2147483647),
    'BigIntegerField ': (- 9223372036854775808,9223372036854775807),
    ' PositiveSmallIntegerField ':( 0,32767),
    ' PositiveIntegerField ':( 0,2147483647),
  }
12 is, models.IPAddressField string type (IP4 regular expressions)
13 is, characters models.GenericIPAddressField string type (IP4 and ip6 optional)
  parameters may be protocol: both, ipv4, ipv6
  verification will be given according to the setting
14, models.NullBooleanField allow boolean empty
15, models.PositiveIntegerFiel positive Integer
16, Models.PositiveSmallIntegerField  正smallInteger
17, models.SlugField minus sign, underscore, letters, numbers
18, models.SmallIntegerField digital
  database field has: tinyint, smallint The, int, BIGINT
. 19, models.TextField string LONGTEXT =
20 is, models.TimeField Time HH: MM [: SS [.uuuuuu]]
21, models.URLField strings, regular expressions address
22, models.BinaryField binary
23, models.ImageField picture
24, models.FilePathField file

Second, the field parameter

1, null = True
  database whether the field can be null
2, blank = True
  if the allowable data is added django Admin is the null value
3, primary_key = False
  primary key, after AutoField set the primary key, it will replace the original self-energizing id column
4, auto_now and auto_now_add
  auto_now automatically create --- whether to add or modify, the current operation is time
  auto_now_add --- always automatically creates time it was created
. 5, choices
GENDER_CHOICE = (
(u'M ', u'Male '),
(u'F', u'Female '),
)
Gender = models.CharField (MAX_LENGTH = 2, = GENDER_CHOICE choices)
. 6, MAX_LENGTH
. 7, default default
8, the name of a field in verbose_name Admin
9, name | db_column field names in the database
10, unique = True allowed to repeat
11, db_index = True database index
12, editable = True in the Admin is editable
13, error_messages = None error
14, auto_created = False automatically create
15, help_text Help information Admin,
16, validators = []
. 17, to-Upload

 

Guess you like

Origin www.cnblogs.com/jiangxiaobo/p/12425273.html