1、sqlitestudio-2.1.5数据库可视化工具--百度云盘下载 

2、编写C:\djangoweb\helloworld\blog\models.py文件
# Create your models here.
#coding:utf-8
from django.db import models
class Student(models.Model):
name=models.CharField(max_length=50)
age=models.IntegerField() 3、配置C:\djangoweb\helloworld\helloworld\setting.py的DATABASES变量
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2sqlite3', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'test.db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
} 4、同步数据库(之前创建数据库删掉)
c:\djangoweb\helloworld>manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table blog_student You just installed Django's auth system, which means you don't have any superuse
rs defined.
Would you like to create one now? (yes/no): no #是否创建超级用户?这里我选择了no
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
c:\djangoweb\helloworld> 5、C:\djangoweb\helloworld\blog\models.py文件新增intime数据类型
# Create your models here.
#coding:utf-8 from django.db import models
class Student(models.Model):
name=models.CharField(max_length=50)
age=models.IntegerField()
intime=models.DateTimeField() #新增 6、数据库同步,将新增的model中的内容更新到数据库中
【注意事项】
1)这里需要删除掉之前的数据库中对应的表再同步数据库(鼠标右键点击blog_student表,在下拉菜单中选择“删除表”),
2)尽量不要直接删除数据库,如果里面有数据那么就完蛋了
c:\djangoweb\helloworld>manage.py syncdb 7、反向同步数据库
1)在sqlite3可视化工具中添加新的数据类型,给student添加sex数据类型数据
2)新增teacher表,并创建id和name2个数据类型
3)执行反向同步数据库,manage.py inspectdb
4)效果:
c:\djangoweb\helloworld>manage.py inspectdb
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field na
s.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [a
name]'
# into your database.
from __future__ import unicode_literals from django.db import models class AuthGroup(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=80, unique=True)
class Meta:
db_table = 'auth_group' class AuthGroupPermissions(models.Model):
id = models.IntegerField(primary_key=True)
group_id = models.IntegerField()
permission = models.ForeignKey('AuthPermission')
class Meta:
db_table = 'auth_group_permissions' class AuthPermission(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
content_type_id = models.IntegerField()
codename = models.CharField(max_length=100)
class Meta:
db_table = 'auth_permission' class AuthUser(models.Model):
id = models.IntegerField(primary_key=True)
password = models.CharField(max_length=128)
last_login = models.DateTimeField()
is_superuser = models.BooleanField()
username = models.CharField(max_length=30, unique=True)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.CharField(max_length=75)
is_staff = models.BooleanField()
is_active = models.BooleanField()
date_joined = models.DateTimeField()
class Meta:
db_table = 'auth_user' class AuthUserGroups(models.Model):
id = models.IntegerField(primary_key=True)
user_id = models.IntegerField()
group = models.ForeignKey(AuthGroup)
class Meta:
db_table = 'auth_user_groups' class AuthUserUserPermissions(models.Model):
id = models.IntegerField(primary_key=True)
user_id = models.IntegerField()
permission = models.ForeignKey(AuthPermission)
class Meta:
db_table = 'auth_user_user_permissions' class BlogStudent(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
age = models.IntegerField()
intime = models.DateTimeField()
sex = models.IntegerField()
class Meta:
db_table = 'blog_student' class DjangoAdminLog(models.Model):
id = models.IntegerField(primary_key=True)
action_time = models.DateTimeField()
user = models.ForeignKey(AuthUser)
content_type = models.ForeignKey('DjangoContentType', null=True, blank=Tru object_id = models.TextField(blank=True)
object_repr = models.CharField(max_length=200)
action_flag = models.PositiveSmallIntegerField()
change_message = models.TextField()
class Meta:
db_table = 'django_admin_log' class DjangoContentType(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100)
app_label = models.CharField(max_length=100)
model = models.CharField(max_length=100)
class Meta:
db_table = 'django_content_type' class DjangoSession(models.Model):
session_key = models.CharField(max_length=40, unique=True)
session_data = models.TextField()
expire_date = models.DateTimeField()
class Meta:
db_table = 'django_session' class DjangoSite(models.Model):
id = models.IntegerField(primary_key=True)
domain = models.CharField(max_length=100)
name = models.CharField(max_length=50)
class Meta:
db_table = 'django_site' class Teacher(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
class Meta:
db_table = 'teacher'
c:\djangoweb\helloworld> 8、修改C:\djangoweb\helloworld\blog\models.py文件
# Create your models here.
#coding:utf-8
from django.db import models
"""
class Student(models.Model):
name=models.CharField(max_length=50)
age=models.IntegerField()
intime=models.DateTimeField()
"""
#修改为:
class Student(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
age = models.IntegerField()
intime = models.DateTimeField()
sex = models.IntegerField()
class Meta:
db_table = 'student' 9、删除“blog_student”表并同步数据库manage.py syncdb 10、将数据类型等信息输出到models.py文件中
1)manage.py inspectdb > blog/models.py
2)查看models文件内容(删除多余后的效果):
from django.db import models
class Student(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
age = models.IntegerField()
intime = models.DateTimeField()
sex = models.IntegerField()
class Meta:
db_table = 'student' class Teacher(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
class Meta:
db_table = 'teacher'

百度云盘:django之创建第8个项目-数据库配置及同步研究

django之创建第8个项目-数据库配置及同步研究的更多相关文章

  1. django之创建第8-3个项目-数据库数据提取之高级操作

    1.配置test2.html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  2. django之创建第8-1个项目-数据库之增删改查/数据库数据显示在html页面

    1.为test.DB数据库预先创建下面数据 1    张三    16    2015-01-02    12    李四    17    2015-01-04    13    王五    14  ...

  3. django之创建第7-2个项目-url配置分离

    1.urls.PY分离 # -*- coding: UTF-8 -*- from django.conf.urls import patterns, include, url # Uncomment ...

  4. django之创建第7个项目-url配置

    1.配置urls.py from django.conf.urls import patterns, include, url #Uncomment the next two lines to ena ...

  5. django之创建第8-2个项目-数据库数据提取之过滤操作符相关

    """1)age__gt = 16等价于age > 162)age = 163)age__gte = 16等价于age >= 164)name__contai ...

  6. django之创建第7-1个项目-url配置高级

    修改urls.PY文件 # -*- coding: UTF-8 -*- from django.conf.urls import patterns, include, url # Uncomment ...

  7. django之创建第11个项目-页面整合

    目的:将如下众多html页面整合到一个index.html页面中. 百度云盘:django之创建第11个项目-页面整合 用下面的方式实现: <!DOCTYPE html> <head ...

  8. django之创建第10-1个项目-图片上传并记录上传时间

    1.百度云盘:django之创建第10-1个项目-图片上传并记录上传时间 2.主要修改的配置文件有3个,forms.views和models3个文件以及html 3.forms.py文件修改 #cod ...

  9. django之创建第10个项目-图片上传方式1

    1.upload.HTMl <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang=& ...

随机推荐

  1. cat、tac、rev、nl命令

    当日志文件log.log很长,但又要按内容从后往前查看时,可以使用如下命令: tac log.log | more cat     由第一行开始显示内容,并将所有内容输出    tac     从最后 ...

  2. Android Studio导入项目的中文注释乱码解决方法

           在Android studio中,导入Android的项目后,容易出现项目文件的中文乱码,中文无法正常显示,变成了一些格子问号之类的,导致无法查看中文的注释,下面来看看导入项目和解决乱码 ...

  3. UML类图和时序图

    这里不会将UML的各种元素都提到,我只想讲讲类图中各个类之间的关系: 能看懂类图中各个类之间的线条.箭头代表什么意思后,也就足够应对 日常的工作和交流: 同时,我们应该能将类图所表达的含义和最终的代码 ...

  4. Eclipse Debug提示source not found解决方案

    场景:我在引用的jar包的某个class文件的某一行代码打了个断点,当然我是已经指定了source源码包路径,否则我是查看不了class文件的源码更不用说打断点了,但是在debug模式下,却提示&qu ...

  5. iOS蓝牙空中升级(固件升级)

    空中升级又叫固件升级,指你手机从服务器下载下来的包或者数据,通过蓝牙传输给你的外设升级固件.如果你能把蓝牙的基础搞懂,其实也并不是很难,我在这里只不过提供一下思路. 空中升级略难的地方在于数据处理和交 ...

  6. Spring系列:Scheduled注解学习笔记

    一.试验代码 //@Scheduled(fixedRate = 5000) //@Scheduled(fixedDelay = 5000) @Scheduled(cron ="*/5 * * ...

  7. Maven WEB 项目使用ProGuard进行混淆,最佳解决方案

    Maven WEB 项目使用ProGuard进行混淆,最佳解决方案 近期公司的Android项目做了混淆,虽说对于保护代码并不是100%的,但混淆后的代码可以使那些不法份子难以阅读,这样也能对代码的保 ...

  8. 微信小程序表单校验WxValidate.js使用

    WxValidate插件是参考 jQuery Validate 封装的,为小程序表单提供了一套常用的验证规则,包括手机号码.电子邮件验证等等,同时提供了添加自定义校验方法,让表单验证变得更简单. 首先 ...

  9. python3 中对arrow库的总结(转发)

    https://blog.csdn.net/soft_kind/article/details/80614896 arrow库的官方文档:http://arrow.readthedocs.io/en/ ...

  10. 【应用】R--判断类别型属性之间是否有相关性(相互之间是否独立)

    检验某学区所有在售房源中,小区与楼栋类别(低层:多层;小高层:高层)是否相关 导入数据: > house<- read.table("house_data.txt", ...