Backend/Django

Django 파이썬 장고 DB 연결

쏠솔랄라 2023. 7. 13. 09:13

 

 

Django 장고 DB 연결

 

 

Model(DB)

: Django 프로젝트에서 DB와 연결

 

 

별도의 모듈을 설치해 주어야 한다 ; DB마다 다름

Oracle : cx_Oracle

MySQL : mysqlclient

 

 

SQL Developer 세팅

 

 

아이디, 계정 생성

Oracle SQL Developer에서 아이디, 계정 생성

alter session set"_ORACLE_SCRIPT"=true;
create USER django IDENTIFIED BY django;

 

 

Oracle SQL Developer 다운로드 및 세팅

https://developernew.tistory.com/39

 

SQLD Oracle Database XE & Oracle SQL Developer 설치 (학습용)

SQLD 시험 공부(학습용)를 위해 SQLD를 수행할 수 있는 Oracle Database XE와 Oracle SQL Developer를 설치하겠습니다 먼저 Oracle Database XE 설치입니다 https://www.oracle.com/database/technologies/xe-downloads.html Oracle Databas

developernew.tistory.com

 

 

Django 장고 세팅

 

 

Python 파이썬 다운로드 및 세팅

https://developernew.tistory.com/182

 

Python 파이썬 다운로드 및 기본 세팅 + VS Code 설정

파이썬 다운로드 https://www.python.org/ Welcome to Python.org The official home of the Python Programming Language www.python.org 메인페이지 접속 > 다운로드 > Python 3.11.4 버전 다운로드 3.7 버전의 경우 2023.6.27 글쓴 날 기

developernew.tistory.com

 

Django 장고 설치 및 세팅 

https://developernew.tistory.com/219

 

Django 장고 프레임워크 설치 및 기본 세팅

Django : 웹을 만들어 가면서 할 수 있는 프로그램 https://www.djangoproject.com/ Django The web framework for perfectionists with deadlines. www.djangoproject.com Django 페이지로 이동 최신 버전은 4.2.3인데 버전 호환성을 고

developernew.tistory.com

 

 

 

 

'DB'로 새 프로젝트 생성

django-admin startproject 프로젝트명

./DB/managy.py runserver로 프로그램을 실행해 연결 확인

 

 

 

 

장고에서 수퍼 계정 생성

python manage.py createsuperuser

 

 

DB > DB > settings.py

 

 

세팅 폴더에 로그인 정보 입력

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'SID',
'USER': '유저ID',
'PASSWORD': '비밀번호',
'HOST': '호스트', 'PORT': '1521',
}
}

 

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': 'XE',
        'USER': 'django',
        'PASSWORD': 'django',
        'HOST': '127.0.0.1',
        'PORT': '1521',
    }
}

 

 

 

cmd 세팅

 

 

 

cmd 창에서 오라클 모듈 설치

pip install cx_Oracle

만약 오류가 난다면 버전에 맞추어 Django 또는 oracle 설치가 필요하다

 

 

 

 

pip install django==3.2.20

성공적으로 설치가 완료되면 프로젝트 db 세팅

 

python ./DB/manage.py inspectdb