자주 묻는 질문: 데이터베이스와 모델Link to this heading

어떻게 장고가 작동시키는 순수 SQL 쿼리를 볼 수 있나요?Link to this heading

Make sure your Django DEBUG setting is set to True. Then do this:

Code
>>> from django.db import connection
>>> connection.queries
[{'sql': 'SELECT polls_polls.id, polls_polls.question, polls_polls.pub_date FROM polls_polls',
'time': '0.002'}]

connection.queriesDEBUG``True``일떄만 가능합니다. 이것은 쿼리가 실행되는 순서대로 작성된 딕셔너리 리스트입니다. 각각의 딕셔너리는 다음을 가지고 있습니다.

Code
``sql`` -- The raw SQL statement
``time`` -- How long the statement took to execute, in seconds.

connection.queries 는 모든 SQL 표현문을 포함합니다. INSERT, UPDATES, SELET 등. 당신의 앱이 데이터베이스에 쿼리할 때마다, 쿼리들이 기록됩니다.

만약 다수의 데이터베이스,를 사용한다면, connections 딕셔너리의 각각에 멤버들에 같은 인터페이스를 사용할 수 있다.

Code
>>> from django.db import connections
>>> connections['my_db_alias'].queries

If you need to clear the query list manually at any point in your functions, call reset_queries(), like this:

Code
from django.db import reset_queries
reset_queries()

장고를 이미 존재하는 데이터베이스와 함께 사용할 수 있나요?Link to this heading

네, :doc:`기존 데이터베이스와 통합 </howto/legacy-databases>`를 보세요

만약 모델에 변화가 생기면, 어떻게 데이터베이스에 적용하나요?Link to this heading

:mod:`schema migrations <django.db.migrations>`라는 장고 지원문서를 참조하세요.

데이터가 지워지는 것을 개의치 않는다면, 프로젝트의 “manage.py” 유틸리티는 flush 옵션을 가지고있어서 :djadmin:`migrate`가 실행된 후의 데이터베이스 상태로 되돌려 줍니다.

장고 모델들은 다중 열 기본 키를 지원하나요?Link to this heading

아니요. 오직 하나의 기본 키만 지원합니다.

But this isn’t an issue in practice, because there’s nothing stopping you from adding other constraints (using the unique_together model option or creating the constraint directly in your database), and enforcing the uniqueness at that level. Single-column primary keys are needed for things such as the admin interface to work; e.g., you need a single value to specify an object to edit or delete.

장고는 NoSQL 데이터베이스를 지원하나요?Link to this heading

NoSQL databases are not officially supported by Django itself. There are, however, a number of side projects and forks which allow NoSQL functionality in Django.

You can take a look on the wiki page which discusses some projects.

어떻게하면 MyISAM을 테이블 타입에 주는것과 같은 데이터베이스 전용 옵션을 CREATE TABLE 명령에 추가할 수 있을까요?Link to this heading

저희는 데이터베이스 마다 가지고있는 옵션들 예를들면 테이블 타입과 같은 것들을 호환하기 위해 특이 사항들을 추가하는 것을 꺼려합니다. 만약 당신이 이런 옵션들을 쓰고 싶다면, 당신이 하고자 하는 것을 가지고있는 :class:`~django.db.migrations.operations.RunSQL`의 ``ALTER TABLE``명령어를 활용하여 마이그레이션을 만드세요.

예를들면, 만약 MySQL을 사용하고 테이블이 MyISAM 테이블 타입을 사용하기 원한다면 다음과 같은 SQL을 사용하세요.

Code
ALTER TABLE myapp_mytable ENGINE=MyISAM;