Make sure your Django DEBUG
setting is set to True
.
Then do this:
>>> 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.queries
는 DEBUG
가 ``True``일떄만 가능합니다. 이것은 쿼리가 실행되는 순서대로 작성된 딕셔너리 리스트입니다. 각각의 딕셔너리는 다음을 가지고 있습니다.
``sql`` -- The raw SQL statement
``time`` -- How long the statement took to execute, in seconds.
connection.queries
는 모든 SQL 표현문을 포함합니다. INSERT, UPDATES, SELET 등. 당신의 앱이 데이터베이스에 쿼리할 때마다, 쿼리들이 기록됩니다.
만약 다수의 데이터베이스,를 사용한다면, connections
딕셔너리의 각각에 멤버들에 같은 인터페이스를 사용할 수 있다.
>>> 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:
from django.db import reset_queries
reset_queries()
:mod:`schema migrations <django.db.migrations>`라는 장고 지원문서를 참조하세요.
데이터가 지워지는 것을 개의치 않는다면, 프로젝트의 "manage.py" 유틸리티는 flush
옵션을 가지고있어서 :djadmin:`migrate`가 실행된 후의 데이터베이스 상태로 되돌려 줍니다.
아니요. 오직 하나의 기본 키만 지원합니다.
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 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.
저희는 데이터베이스 마다 가지고있는 옵션들 예를들면 테이블 타입과 같은 것들을 호환하기 위해 특이 사항들을 추가하는 것을 꺼려합니다. 만약 당신이 이런 옵션들을 쓰고 싶다면, 당신이 하고자 하는 것을 가지고있는 :class:`~django.db.migrations.operations.RunSQL`의 ``ALTER TABLE``명령어를 활용하여 마이그레이션을 만드세요.
예를들면, 만약 MySQL을 사용하고 테이블이 MyISAM 테이블 타입을 사용하기 원한다면 다음과 같은 SQL을 사용하세요.
ALTER TABLE myapp_mytable ENGINE=MyISAM;
8월 03, 2020