auto_cmdb--01之models.py建表

1.创建一个auto_cmdb的python项目,在auto_cmdb下创建一个app01

2.连接mysql

在seeting中配置

DATABASES = {

‘default‘: {

‘ENGINE‘: ‘django.db.backends.mysql‘,

‘NAME‘:‘auto_cmdb‘,

‘USER‘: ‘root‘,

‘PASSWORD‘: ‘123456‘,

‘HOST‘: ‘10.10.20.134‘,

‘PORT‘: ‘‘

}

}

3.models.py建立表结构

使用python manage.py migrate

报错:ImportError: No module named rest_framework

处理:pip install djangorestframework

报错:ImportError: No module named daterange_filter

处理:pip install django-daterange-filter

报错:ImportError: No module named import_export

处理:pip install django-import-export

[[email protected] auto_cmdb]# python manage.py migrate

System check identified some issues:

WARNINGS:

app01.ApiAuth.users: (fields.W340) null has no effect on ManyToManyField.

app01.Asset.cabinet_order: (fields.W122) ‘max_length‘ is ignored when used with IntegerField

HINT: Remove ‘max_length‘ from field

app01.Maintainence.maintain_type: (fields.W122) ‘max_length‘ is ignored when used with IntegerField

HINT: Remove ‘max_length‘ from field

app01.NIC.ipaddr: (fields.W900) IPAddressField has been deprecated. Support for it (except in historical migrations) will be removed in Django 1.9.

HINT: Use GenericIPAddressField instead.

app01.Server.software: (fields.W340) null has no effect on ManyToManyField.

app01.Software.types: (fields.W122) ‘max_length‘ is ignored when used with IntegerField

HINT: Remove ‘max_length‘ from field

Operations to perform:

Synchronize unmigrated apps: django_filters, staticfiles, messages, daterange_filter, import_export, rest_framework

Apply all migrations: admin, contenttypes, app01, auth, sessions

Synchronizing apps without migrations:

Creating tables...

Running deferred SQL...

Installing custom SQL...

Running migrations:

Rendering model states... DONE

Applying contenttypes.0001_initial... OK

Applying auth.0001_initial... OK

Applying admin.0001_initial... OK

Applying app01.0001_initial... OK

Applying app01.0002_auto_20141110_0740... OK

Applying app01.0003_auto_20141110_0754... OK

Applying app01.0004_auto_20141117_0848... OK

Applying app01.0005_auto_20141118_0917... OK

Applying app01.0006_server_software... OK

Applying app01.0007_auto_20141119_0741... OK

Applying app01.0008_auto_20141120_0137... OK

Applying app01.0009_auto_20141120_0317... OK

Applying app01.0010_auto_20141120_0556... OK

Applying app01.0011_auto_20141120_0725... OK

Applying app01.0012_auto_20141120_0916... OK

Applying app01.0013_cpu_parent_sn... OK

Applying app01.0014_auto_20141121_0625... OK

Applying app01.0015_auto_20141121_0627... OK

Applying app01.0016_auto_20141124_0240... OK

Applying app01.0017_auto_20141124_0333... OK

Applying app01.0018_auto_20141124_0520... OK

Applying app01.0019_auto_20141124_0820... OK

Applying app01.0020_asset_hostname... OK

Applying app01.0021_auto_20141124_1116... OK

Applying app01.0022_auto_20141125_0927... OK

Applying app01.0023_auto_20141125_1126... OK

Applying app01.0024_auto_20141126_0150... OK

Applying app01.0025_auto_20141126_0154... OK

Applying app01.0026_auto_20141126_0502... OK

Applying app01.0027_auto_20141126_0516... OK

Applying app01.0028_auto_20141126_0924... OK

Applying app01.0029_auto_20141201_2033... OK

Applying app01.0030_eventlog... OK

Applying app01.0031_server_manufactory... OK

Applying app01.0032_eventlog_create_at... OK

Applying app01.0033_server_model... OK

Applying app01.0034_auto_20141203_1450... OK

Applying app01.0035_remove_asset_sn... OK

Applying app01.0036_auto_20141203_1651... OK

Applying app01.0037_auto_20141204_0857... OK

Applying app01.0038_auto_20141204_0901... OK

Applying app01.0039_auto_20141204_1524... OK

Applying app01.0040_auto_20141204_1833... OK

Applying app01.0041_auto_20141204_1935... OK

Applying app01.0042_auto_20141204_2315... OK

Applying app01.0043_asset_asset_op... OK

Applying app01.0044_auto_20141205_2004... OK

Applying app01.0045_auto_20141205_2241... OK

Applying app01.0046_auto_20141205_2249... OK

Applying app01.0047_auto_20141219_0908... OK

Applying contenttypes.0002_remove_content_type_name... OK

Applying auth.0002_alter_permission_name_max_length... OK

Applying auth.0003_alter_user_email_max_length... OK

Applying auth.0004_alter_user_username_opts... OK

Applying auth.0005_alter_user_last_login_null... OK

Applying auth.0006_require_contenttypes_0002... OK

Applying sessions.0001_initial... OK

大功告成!

时间: 2024-12-20 01:09:58

auto_cmdb--01之models.py建表的相关文章

第三百七十五节,Django+Xadmin打造上线标准的在线教育平台—创建课程机构app,在models.py文件生成3张表,城市表、课程机构表、讲师表

第三百七十五节,Django+Xadmin打造上线标准的在线教育平台-创建课程机构app,在models.py文件生成3张表,城市表.课程机构表.讲师表 创建名称为app_organization的课程机构APP,写数据库操作文件models.py models.py文件 #!/usr/bin/env python # -*- coding:utf-8 -*- from __future__ import unicode_literals from datetime import datetim

第三百七十六节,Django+Xadmin打造上线标准的在线教育平台—创建用户操作app,在models.py文件生成5张表,用户咨询表、课程评论表、用户收藏表、用户消息表、用户学习表

第三百七十六节,Django+Xadmin打造上线标准的在线教育平台-创建用户操作app,在models.py文件生成5张表,用户咨询表.课程评论表.用户收藏表.用户消息表.用户学习表 创建名称为app_operation的用户操作APP,写数据库操作文件models.py models.py文件 #!/usr/bin/env python # -*- coding:utf-8 -*- from __future__ import unicode_literals from datetime i

四 Django框架,models.py模块,数据库操作——创建表、数据类型、索引、admin后台,补充Django目录说明以及全局配置文件配置

Django框架,models.py模块,数据库操作--创建表.数据类型.索引.admin后台,补充Django目录说明以及全局配置文件配置 数据库配置 django默认支持sqlite,mysql, oracle,postgresql数据库. 1,django默认使用sqlite的数据库,默认自带sqlite的数据库驱动   引擎名称:django.db.backends.sqlite3 在全局配置文件settings.py可以看到确认配置使用的sqlite数据库 # Database # h

django models.py增加后MySQL数据库中并没有生成相应的表

根据教程到添加并保存quest的时候报错了 1.models.py里面的命名没有错 2.查看mysite->settiongs下的INSTALLED_APPS设置正确 3.使用python manage.py makemigrations polls没有修改的内容 4.查看0001_***.py正常 解决方法: 1.删掉migrations下的除了__init__.py以为的所有文件 2.python manage.py makemigrations polls 3.python manage.

通过pymysql和数据模型(models.py)创建mysql表及表结构

一.model的配置 1.创建数据库 2.安装pymysql 3.修改配置文件 数据库连接配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'stu',    #数据库名 'USER':'root',    #登录用户名 'PASSWORD':'123456',  #登录密码 'HOST':'127.0.0.1', #服务器地址 'PORT':'3306',   #数据库端口号 }} 把当前的应

django 使用原生SQL语句反向生成MODELS.PY中的表结构

在一次工作中,有这么一个问题,就是要导入的数据字段不确定,但是还想使用django的ORM来对数据进行操作.. 琢磨了许久,弄个不完善的方案,但功能是能实现的,主要是思路.废话不多说了,丑陋的展示一下吧... from django.db import connection #粗陋的用数组和字符串表示一下要导入的数据表单项lis = ['ll', 'bb', 'yy'] #表示要建立的表单字段l = 'tablename' #表名ll = 'fff' new_table = connection

django模型models.py文件内容理解

首先,要理解这句话:模型是你的数据的唯一的.权威的信息源.它包含你所存储数据的必要字段和行为.通常,每个模型对应数据库中唯一的一张表 基础:每个模型都是django.db.models.Model的一个python子类 模型的每个属性都表示为数据库中的一个字段 django提供一套自动生成的用于数据库访问的API,下一章总结 1.第一个例子 from django.db import models class Person(models.Model): first_name = models.C

表操作--建表语句

表操作--建表语句 1.创建默认字符集库 下面已默认格式的字符集库 mysql> create database Ysolin; Query OK, 1 row affected (0.00 sec) mysql> show create database Ysolin\G *************************** 1. row *************************** Database: Ysolin Create Database: CREATE DATABAS

magic操作数据库建表总结

Magic创建表总结 Magic创建表(数据库oracle为例) 首先创建项目: File——new project(project name起名)——(local files folder 选取路径) 创建完项目需要与数据库建立连接: 创建项目页面(菜单栏 opens the database repository)——ctrl+F4(添加新一行)(name名,建表指定的database name)(database name 方便指定识别哪个数据库)(dbms连接数据库类型)——制定建立哪个