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. Java多线程之Callable接口与Runnable的实现以及选择

    通过实现Runnable接口的实现 package Thread; import java.util.concurrent.ExecutorService;import java.util.concu ...

  2. tcp常见状态

    常见状态 1.建立连接 2.关闭连接

  3. delete method not allowed 405错误

    造成该问题的原因:iis版本问题 解决办法如下: 修改配置文件web.config <system.webServer><modules><remove name=&qu ...

  4. arcgis server 10 for java 8399根目录是404的提示取消,并跳转到 地图目录 /arcgis/rest/services下

    看了Howto: 取消ArcGIS Server 9.x for Java内置tomcat在8399端口的文件列表 http://support.esrichina-bj.cn/2009/0819/9 ...

  5. C#中byte[] 转 double[] 或 int[] 或 struct结构体

    方法:使用C#调用C++ memcpy实现各种参数类型的内存拷贝 using System.Runtime.InteropServices; public class GlbWSGridDataset ...

  6. jQuery源码分析-构造函数详解

    在jQuery.js的构造函数中,充分利用了JavsScript语言的动态性——对行参的类型和个数没有的严格要求,以至于一个函数可以实现多种功能需求,也为JavaScript语言的多态性提供了基础,在 ...

  7. 云服务器 ECS Linux Ubuntu 主机修改主机名

    云服务器 ECS Linux 主机修改主机名 修改云服务器 ECS Linux 主机名常见的有两种方式,本文对此进行概要说明. 临时生效修改 使用命令行修改 hostname 主机名(可自定义),重新 ...

  8. 如何查看自己电脑系统的安装日期-Window上

    开始 > 运行(快捷键 Win+R)->敲入 systeminfo | find “初始安装日期”

  9. How to Redirect in ASPNET Web API

      You could set the Location header: public HttpResponseMessage Get() { var response = Request.Creat ...

  10. 保存登录plsql developer 的用户名和密码

    1 保存用户名 tools -> Preferences -> User Interface - Options 勾选 Autosave username . 保存 2 保存密码 tool ...