Django支持很多数据的配置,在次记录下来方便以后使用Django框架时好查找。
默认数据库SQLite3
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
MySQL的配置
'default': {
'ENGINE': 'django.db.backends.mysql',
# the name of database
'NAME': '创建的数据库名称',
'USER': '数据库账号',
'PASSWORD': '******',
'HOST': '主机IP',
'PORT': '端口号',
}
PostgreSQL的配置
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '创建的数据库名称',
'USER': '数据库账号',
'PASSWORD': '******',
'HOST': '主机IP',
'PORT': '端口号',
}
最后一个没有验证过,Django还支持Oracle。Oracle的配置和MySQL、PostgreSQL是一样的,只是需要将ENGINE修改为'django.db.backends.oracle'
即可。
数据库类型 | ENGINE | NAME |
---|---|---|
SQLite3 | django.db.backends.sqlite3 | os.path.join(BASE_DIR, 'db.sqlite3') |
MySQL | django.db.backends.mysql | 创建的数据库的名称 |
postgresql | django.db.backends.postgresql | 创建的数据库的名称 |
Oracle | django.db.backends.oracal | 创建的数据库的名称 |
........... | ............................................... | .............................................. |
PS:如果不使用默认的SQLite3,则必须有user、password、host。
If you’re using SQLite, you don’t need to create anything beforehand - the database file will be created automatically when it is needed.
——http://devdocs.io
网友评论