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. [转]php判断一个数组是另一个数组的子集

    FROM : http://blog.csdn.net/lcion/article/details/8985220 今天完成一个算法的过程中,有几个需求模块,其中就有判断$a数组是否是$b数组的子集, ...

  2. IDEA重写toString()模板,转成json格式

    1.类中Alt + Insert,弹出下框 2.点击新增 public java.lang.String toString() { final java.lang.StringBuilder sb = ...

  3. JavaScript:ECMAScript 引用类型

    ylbtech-JavaScript:ECMAScript 引用类型 1. 返回顶部 2. ECMAScript 引用类型返回顶部 引用类型通常叫做类(class). 本教程会讨论大量的 ECMASc ...

  4. Android Asynchronous Http Client-Android异步网络请求客户端接口

    1.简介 Android中网络请求一般使用Apache HTTP Client或者采用HttpURLConnect,但是直接使用这两个类库需要写大量的代码才能完成网络post和get请求,而使用and ...

  5. TCP UDP Socket 即时通讯 API 示例 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  6. 字符串 CSV解析 表格 逗号分隔值 通讯录 电话簿 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  7. Laravel validate 500异常 添加手机验证,中文验证与Validator验证的“半个”生命周期

    今天来讲一下,Lumen的Validator函数 1 2 3 4 5 6 7 8 9 10 11 use Validator;   ...   Class .. {   public function ...

  8. JAVA的Split小技巧

    在日常的开发中截取字符串必不可少,但是在JAVA中的Split截取有点特点的地方是         例如:            String str=1,2,3,; 那么  str.split(&q ...

  9. ARM 汇编的mov操作立即数的疑问

    1. 因为对arm汇编有些指令还不能理解,特别是一些相似功能指令间的区别.偶然在网上搜到"faq ARM assembly",其中描述的几个问题还是值得好好研究一下. 2. 慢慢的 ...

  10. 例子:使用Grunt创建一个Node.js类库

      创建一个文件夹. 打开命令行或者powershell, 运行npm init,根据提示填入package的信息. 在文件夹中创建index.js文件. /*! * mymongolib * Cop ...