四、创建后台管理账号、迁移数据库

四、创建后台管理账号、迁移数据库

前面三个应用的模型都创建好了,现在需要把它们迁移至数据库

python manage.py makmigrations

Migrations for 'blog':
  blog\migrations\0001_initial.py
    - Create model Category
    - Create model Post
    - Create model Tag
    - Add field tag to post
Migrations for 'comment':
  comment\migrations\0001_initial.py
    - Create model Comment
Migrations for 'config':
  config\migrations\0001_initial.py
    - Create model Link
    - Create model SideBar

python manage.py migrate

Operations to perform:
  Apply all migrations: admin, auth, blog, comment, config, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying blog.0001_initial... OK
  Applying comment.0001_initial... OK
  Applying config.0001_initial... OK
  Applying sessions.0001_initial... OK

数据库迁移完毕后,每个应用的migrations文件内会出现一个0000_initial.py文件,它记录了对象模型的更改。在后面的开发过程中,如果改动了模型,就应该再一次迁移数据库。这里数据库开发阶段还是使用sqllite,后面进入生产环境中时,我们再配置MySQL

接下来创建后台管理帐户

python manage.py createsuperuser

四、创建后台管理账号、迁移数据库_第1张图片
image

运行服务进入后台试一下,http://127.0.0.1:8000/admin/

python manage.py runserver

GitHub
欢迎访问Treehl的博客

你可能感兴趣的:(四、创建后台管理账号、迁移数据库)