官术网_书友最值得收藏!

Running our initial migration

Now, it is necessary to create the initial migration for the new Toy model we recently coded. We will also synchronize the SQLite database for the first time. By default, Django uses the popular self-contained and embedded SQLite database, and therefore we don't need to make changes in the initial ORM configuration. In this example, we will be working with this default configuration. Of course, we will upgrade to another database after we have a sample web service built with Django. We will only use SQLite for this example.

We just need to run the following Python script in the virtual environment that we activated in the previous chapter. Make sure you are in the restful01 folder within the main folder for the virtual environment when you run the following command:

    python manage.py makemigrations toys  

The following lines show the output generated after running the previous command:

    Migrations for 'toys':
      toys/migrations/0001_initial.py:
        - Create model Toy

The output indicates that the restful01/toys/migrations/0001_initial.py file includes the code to create the Toy model. The following lines show the code for this file that was automatically generated by Django. The code file for the sample is included in the hillar_django_restful_02_01 folder in the restful01/toys/migrations/0001_initial.py file:

# -*- coding: utf-8 -*- 
# Generated by Django 1.11.5 on 2017-10-08 05:19 
from __future__ import unicode_literals 
 
from django.db import migrations, models 
 
 
class Migration(migrations.Migration): 
 
    initial = True 
 
    dependencies = [ 
    ] 
 
    operations = [ 
        migrations.CreateModel( 
            name='Toy', 
            fields=[ 
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 
                ('created', models.DateTimeField(auto_now_add=True)), 
                ('name', models.CharField(default='', max_length=150)), 
                ('description', models.CharField(blank=True, default='', max_length=250)), 
                ('toy_category', models.CharField(default='', max_length=200)), 
                ('release_date', models.DateTimeField()), 
                ('was_included_in_home', models.BooleanField(default=False)), 
            ], 
            options={ 
                'ordering': ('name',), 
            }, 
        ), 
    ] 
主站蜘蛛池模板: 霞浦县| 克什克腾旗| 邯郸市| 泽普县| 屏东市| 利川市| 昌乐县| 龙泉市| 隆安县| 株洲市| 阿巴嘎旗| 冀州市| 丁青县| 郓城县| 长治县| 新巴尔虎右旗| 诸暨市| 容城县| 四子王旗| 乌兰浩特市| 马龙县| 仙游县| 镇坪县| 上高县| 安化县| 阜平县| 盘锦市| 遵义市| 克什克腾旗| 北碚区| 松溪县| 济源市| 潼关县| 江门市| 获嘉县| 通辽市| 开封市| 营山县| 乐都县| 门头沟区| 常熟市|