1,查询所有数据库命令:show databases;
2,进入某个数据库命令:ues Name database(数据库名称);
3,展示某个数据库的表命令:show tables;
4,查看某个表内容:select * from 表名;
5,查看表的数据结构:desc 表名;
学生表插入数据:department_id与数据库一致
Student.objects.create(s_name="李雷", department_id=1)
<Student: Student:s_id:4,s_mane:李雷>
学生详情表插入数据:s_id_id与数据库一致
Stu_detail.objects.create(age=18, s_id_id=1)
<Stu_detail: Stu_detail:s_id:Student:s_id:1,s_mane:小明,age:18>
学生表直接插入数据:先构建实例
<Department: Department:d_id:3,d_name:科技大学>
d = Department.objects.get(d_id=3)
Student.objects.create(s_name='嘻嘻',department=d)
<Student: Student:s_id:8,s_mane:嘻嘻>
插入年龄
s1 = Student.objects.get(s_name='嘻嘻')
Stu_detail.objects.create(age=19, s_id=s1)
<Stu_detail: Stu_detail:s_id:Student:s_id:8,s_mane:嘻嘻,age:19>
网友评论