讓Django支援多種資料庫
In a recent Django class one of my students posed the problem she was learning Django to tackle - she would be responsible for writing a web-based administrative interface to a database whose structure she wasn't allowed to modify. Can Django do that?
Absolutely - and Django even comes with a management command to bootstrap working with a legacy database. Let's create a brand new project, use a popular sample database as our target, and using Django's multi-db support to store Django's built-in model data in a separate database.
Installation and setup
For this project I'm using Django 1.3 since that's the version we targeted in the class. All code referenced in the tutorial will be checked into the github project and can be reviewed there. I'm using virtualenv and pip to manage installation of Django, my Python environment, and eventually my third party applications.
$ cd dualdb-project
$ mkvirtualenv django1.3
(django1.3)$ pip install django==1.3
...
Successfully installed django
Cleaning up...
(django1.3)$ django-admin.py startproject dualdb
(django1.3)$ ls dualdb
(django1.3)$ ls -l dualdb/
total 16
-rw-rw-r-- 1 simeon simeon 0 Aug 1 15:20 __init__.py
-rw-rw-r-- 1 simeon simeon 503 Aug 1 15:20 manage.py
-rw-rw-r-- 1 simeon simeon 5031 Aug 1 15:20 settings.py
-rw-rw-r-- 1 simeon simeon 565 Aug 1 15:20 urls.pyNow that I have a new Django project, I need a sample database to look at. The Chinook project provides a sample reference database in various database formats - think a new version of the old Northwind reference database. I downloaded the Sqlite version for our project from the Chinook project website and dropped it in my new dualdb folder. I'm also going to create a "chinook" app to work in.
Absolutely - and Django even comes with a management command to bootstrap working with a legacy database. Let's create a brand new project, use a popular sample database as our target, and using Django's multi-db support to store Django's built-in model data in a separate database.
Installation and setup
For this project I'm using Django 1.3 since that's the version we targeted in the class. All code referenced in the tutorial will be checked into the github project and can be reviewed there. I'm using virtualenv and pip to manage installation of Django, my Python environment, and eventually my third party applications.
CODE:
$ mkdir dualdb-project$ cd dualdb-project
$ mkvirtualenv django1.3
(django1.3)$ pip install django==1.3
...
Successfully installed django
Cleaning up...
(django1.3)$ django-admin.py startproject dualdb
(django1.3)$ ls dualdb
(django1.3)$ ls -l dualdb/
total 16
-rw-rw-r-- 1 simeon simeon 0 Aug 1 15:20 __init__.py
-rw-rw-r-- 1 simeon simeon 503 Aug 1 15:20 manage.py
-rw-rw-r-- 1 simeon simeon 5031 Aug 1 15:20 settings.py
-rw-rw-r-- 1 simeon simeon 565 Aug 1 15:20 urls.pyNow that I have a new Django project, I need a sample database to look at. The Chinook project provides a sample reference database in various database formats - think a new version of the old Northwind reference database. I downloaded the Sqlite version for our project from the Chinook project website and dropped it in my new dualdb folder. I'm also going to create a "chinook" app to work in.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-741253/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- django多資料庫操作Django資料庫
- .NET 百萬級 大資料插入、更新 ,支援多種資料庫大資料資料庫
- 支援多種資料庫型別的遷移工具資料庫型別
- 策略模式實現支援多種類資料庫的DBHelp模式資料庫
- Django 使用心得 (四)多資料庫Django資料庫
- django使用多個資料庫實現Django資料庫
- 探索 Python/Django 支援分散式多租戶資料庫,如 Postgres+CitusPythonDjango分散式資料庫
- Django 1.6釋出 支援持久資料庫連結Django資料庫
- 資料庫Delete的多種用法資料庫delete
- 讓PDF.NET支援最新的SQLite資料庫SQLite資料庫
- Django學習(四)表單,讓資料庫更強大Django資料庫
- Winform開發框架中實現多種資料庫型別切換以及分拆資料庫的支援ORM框架資料庫型別
- django資料庫操作Django資料庫
- Asp.Net Core Identity 多資料庫支援ASP.NETIDE資料庫
- django 配置mysql資料庫DjangoMySql資料庫
- django—資料庫設定Django資料庫
- django操作多資料庫Django資料庫
- Django5—資料庫Django資料庫
- django配置mysql資料庫DjangoMySql資料庫
- 多種方式讀取 MySQL 資料庫配置MySql資料庫
- Spring Boot MyBatis配置多種資料庫Spring BootMyBatis資料庫
- 雲資料庫MongoDB全面支援3.4版本,支援多儲存引擎資料庫MongoDB儲存引擎
- Oracle資料庫中的多種SCN彙總Oracle資料庫
- django | 連線mysql資料庫DjangoMySql資料庫
- django用什麼資料庫Django資料庫
- django資料庫遷移-15Django資料庫
- Django切換MySQL資料庫DjangoMySql資料庫
- django setting 配置資料庫Django資料庫
- C# 連線多種資料庫元件,類庫專案C#資料庫元件
- J2EE 與 多資料庫的支援(迷惑中。。)資料庫
- 分享一個純 Go 編寫的內嵌型 KV 資料庫 NutsDB,支援事務以及多種資料結構Go資料庫資料結構
- 多種資料庫型別管理軟體:DBeaverUltimate中文資料庫型別
- Disk Drill Media Recovery for Mac(支援多種格式的資料恢復工具)Mac資料恢復
- Django資料庫類庫MySQLdb使用詳解Django資料庫MySql
- Django-Multitenant,分散式多租戶資料庫專案實戰(Python/Django+Postgres+Citus)DjangoNaN分散式資料庫Python
- 讓PDF.NET支援不同版本的SQL Server Compact資料庫SQLServer資料庫
- 09.Django-資料庫優化Django資料庫優化
- Django 2連線MySQL資料庫DjangoMySql資料庫