django1.11.1 models 数据库同步方法

yipeiwu_com5年前Python基础

在django1.9之前,数据库同步只需要一条命令:python manage.py syncdb

在djang1.9以后,数据库同步执行指令如下:

同步数据库接口(注意需要切换至python project工作空间所在路径)

python manage.py makemigrations 

同步数据

python manage.py migrations

最后登入http://localhost:8080/admin 发现,已经创建数据库表。

windows10 cmd窗口指令

D:\user_workspace>python manage.py makemigrations
Migrations for 'blog':
 blog\migrations\0001_initial.py
 - Create model BlogPost
D:\user_workspace>python manage.py migrate
Operations to perform:
 Apply all migrations: admin, auth, blog, 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 sessions.0001_initial... OK

以上这篇django1.11.1 models 数据库同步方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

如何在sae中设置django,让sae的工作环境跟本地python环境一致

sae中安装有python环境,想让sae导入自己下载的django或者其他模块,可以在svn中新建一个文件目录,比如site-packages,跟python安装目录一样,这个目录存放...

python解压TAR文件至指定文件夹的实例

如下所示: ######### Extract all files from src_dir to des_dir def extract_tar_files(src_dir,des...

解决python3 安装完Pycurl在import pycurl时报错的问题

此次遇到的问题是在import pycurl 时报错 pycurl:libcurl link-time version is older than compile-time versi...

使用tensorflow实现线性回归

使用tensorflow实现线性回归

本文实例为大家分享了tensorflow实现线性回归的具体代码,供大家参考,具体内容如下 一、随机生成1000个点,分布在y=0.1x+0.3直线周围,并画出来 import ten...

Python生成随机数的方法

如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与random模块中最常用的几个函数的关系,希望你会有所收获,...