1,创建表时加入的约束 a) 非空约束,not null b) 唯一约束,unique c) 主键约束,primary key d) 外键约束,foreign key 1,非空约束,针对某个字段设置其值不为空,如:学生的姓名不能为空 drop table if exists t_student; create table t_student( student_id ), student_name ) not null, sex ) default 'm', birthday date, emai…
EF如何操作内存中的数据和加载外键数据:延迟加载.贪婪加载.显示加载 之前的EF Code First系列讲了那么多如何配置实体和数据库表的关系,显然配置只是辅助,使用EF操作数据库才是每天开发中都需要用的.这个系列讲讲如何使用EF操作数据库. 一.EF小试牛刀 系列文章开始的时候提示大家,必须学会且习惯使用sql Profiler(开始 - 程序 - Microsoft SQL Server 2008 - 性能工具 - Sql Server Profiler),它可以监控到ef生成的sql是什…
class QuestionsModel(models.Model): author = models.ForeignKey(FrontUserModel,null=True) content = models.TextField(null=False) create_time = models.DateTimeField(auto_now_add=True) 1.在questions模型中,有个author外键 2.使用questions = QuestionsModel.objects.al…
一.models.py中 from django.db import models class UserModel(models.Model) user_name = models.CharField() class MyModel(models.Model) author = models.Foreignkey(user) age = models.CharField() 二. 序列化文件 serializers.py 中创建序列化类 from rest_framework.serialize…
有外键的主键设置自增. ; ALTER TABLE `<table>` MODIFY COLUMN `id` ) NOT NULL AUTO_INCREMENT FIRST; 创建数据库,创建新用户,超级用户给新用户赋权 create database dbName; create user userName@'%' identified by 'userPassword'; #创建新用户 grant all privileges on dbName.* to userName@'%';  #…
--首先添加主键约束alter table studentadd constraint PK_student_sno primary key(sno) --删除约束alter table studentdrop constraint PK_student_sno --not nullalter table studentmodify (sname varchar2(30) not null) --check 检查约束alter table studentadd constraint CK_stu…
表关联的问题在开发中是必不可少的,现在我先简单的谈谈我的学习经验.先来说一下外键一对多的问题. 步骤1:准备数据: (1)设计模拟场景: 一个游戏为了测试游戏的运行情况,招来了一批用户来试玩,现需要录入这些用户的基本信息(由于是简易教程,所以我少用些字段) 由于游戏的服务区有四个,所以我需要在四个区域都要用户,将用户分为A,B,C,D四组,现实中的组名服务区肯定字节很长,所以一般会用ID来标记,这样便于加快查询与添加数据的时间效率. (2)创建第一张组名表,起名为fzu: 插入数据: inser…
一.今日内容总结: day62 内容回顾: 1. django有关所有命令: pip install django==1.11.14 django-admin startproject 项目名称 cd 项目 python manage.py runserver 80 0.0.0.0:80 python manage.py startapp app01 python manage.py makemigrations # 保存models修改记录 python manage.py migrate #…
MVC M: model 模型 与数据库交互 V: view 视图 HTML C:controller 控制器 流程 和 业务逻辑 MTV M:model ORM T:template 模板 HTML V:view 视图 业务逻辑 Django中的视图 FBV  def add_publisher(request,*args,**kwargs):  # 逻辑  return  response urls.py   url(r'^add_publisher',add_publisher ) CBV…
use information_schema; show tables; select * from KEY_COLUMN_USAGE where COLUMN_NAME='areaid';…