Django Oracle11g ์ฐ๋
Django ํ๋ ์์ํฌ ์ฌ์ฉํ ๋ Oracle ๋ฒ์ ์ ๋ํ Dependency๊ฐ ์์ต๋๋ค.
https://docs.djangoproject.com/en/2.0/releases/2.0/#dropped-support-for-oracle-11-2
Django 2.0๋ถํฐ Oracle11g์ ๋ํ ์ง์์ ์ค๋จํ๊ฒ ๋์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ 2.X Python๋ ์ง์ํ์ง ์์ต๋๋ค. ๊ทธ๋์ Django ํ๋ ์์ํฌ๋ฅผ ์ด์ฉํ ๊ฐ๋ฐ ์ Oracle Database๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ๋ฒ์ Dependency์๋ํด์ ๊ณ ๋ คํด์ผํฉ๋๋ค.
Django Oracle11g ์ฐ๋ ํธ๋ฒ
ํ์ง๋ง Django 2.X ๋ฒ์ ์์ Oracle11g๋ฅผ ์ฌ์ฉํ ์ ์๋ ํธ๋ฒ์ด ํ๊ฐ์ง ์์ต๋๋ค.
Django 2.X์์ Oracle12c ์ด์์ ์ง์ํ๋ ์ด์ ๋ SQL ๋ฌธ๋ฒ์ด ๋ค๋ฅด๊ฒ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ๋๋ค. Django์ Model์ ๋ค๋ฃฐ ๋ Oracle12c์์ ์ง์ํ๊ณ Oracle11g์์ ์ง์ํ์ง ์๋ ๋ฌธ๋ฒ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ Django 2.X์์ Oracle11g๋ฅผ ์ฌ์ฉํ๋ฉด ์๋์ ๊ฐ์ ์ํ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
- manage.py migrate ํ ๋ SQL๋ฌธ๋ฒ๊ณผ ๊ด๋ จ๋ ์ค๋ฅ ๋ฐ์
- ๊ทธ๋์ django admin์ ํ์ํ ํ ์ด๋ธ๋ค์ ์์ฑํ์ง ๋ชปํ๋ค.
์ด๋ฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด Oracle11g์์ ์ฌ์ฉํ๋ ๊ณ์ ์ ๋ฏธ๋ฆฌ django admin์์ ์ฌ์ฉ๋๋ ์คํค๋ง๋ฅผ ์์ฑํ๋ฉด ์ฌ์ฉํ ์ ์๋ค.
์คํค๋ง๋ฅผ ๋ฏธ๋ฆฌ ์์ฑํด์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ผ๋ก 2๊ฐ์ง๊ฐ ์๋ค.
Django 1.11 ์ค์น ํ 2.X ์ค์น
๋ง์ฝ Oracle11g๋ฅผ ์ฌ์ฉํด์ผํ๋ ํ๊ฒฝ์ด๋ผ๋ฉด Django 1.11์ ๋จผ์ ์ค์นํ๊ณ migrate์ ์งํํด์ admin ํ ์ด๋ธ๋ค์ ์์ฑํ๊ณ Django 2.X๋ก ๋ค์ ์ค์นํด์ ์งํํ๋ฉด ๊ฐ๋ฅํ๋ค.
DDL Script ์ถ์ถ ํ ์ ์ฉ
๋๋ฒ์งธ ๋ฐฉ๋ฒ์ผ๋ก Oracle12c์์ ์ ์ฉ๋ ํ ์ด๋ธ๋ค์ Oracle11g์ ๋ง๊ฒ DDL ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํด์ ์คํค๋ง๋ฅผ ์ ์ํ๋ ๋ฐฉ๋ฒ์ด๋ค.
- Python 3.9.6
- Django 2.2.24
- Oracle11g
- cx_Oracle 8.2
์๋ Script๋ ์์ ํ๊ฒฝ์์ ํ ์คํธํ ์คํค๋ง์ ๋๋ค. Oracle12c์์ ์ถ์ถํ๊ณ Oracle11g์ ๋ง๊ฒ ์์ ํ ๋ด์ฉ์ ๋๋ค.
/*
django 2.X ๋ฒ์ ์์๋ oracle 12c ์ด์ ๋ฒ์ ๋ง ์ง์ํ๋ค.
oracle 11g๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด django admin ์คํค๋ง๋ฅผ ์ฃผ์
ํด์ ์ฌ์ฉํด์ผํ๋ค.
ํ์ ํ
์ด๋ธ๋ค์ ๋ํ ์คํค๋ง ์์ฑ
AUTH_GROUP
DJANGO_CONTENT_TYPE
AUTH_PERMISSION
AUTH_GROUP_PERMISSIONS
DJANGO_MIGRATIONS
DJANGO_SESSION
AUTH_USER
DJANGO_ADMIN_LOG
AUTH_USER_GROUPS
AUTH_USER_USER_PERMISSIONS
*/
--AUTH_GROUP
CREATE TABLE "AUTH_GROUP"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"NAME" NVARCHAR2(150),
PRIMARY KEY ("ID"),
UNIQUE ("NAME")
);
CREATE SEQUENCE "AUTH_GROUP_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "AUTH_GROUP_TR"
BEFORE INSERT ON "AUTH_GROUP"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "AUTH_GROUP_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "AUTH_GROUP_TR" ENABLE;
--DJANGO_CONTENT_TYPE
CREATE TABLE "DJANGO_CONTENT_TYPE"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"APP_LABEL" NVARCHAR2(100),
"MODEL" NVARCHAR2(100),
PRIMARY KEY ("ID"),
CONSTRAINT "DJANGO_CO_APP_LABEL_76BD3D3B_U" UNIQUE ("APP_LABEL", "MODEL")
);
CREATE SEQUENCE "DJANGO_CONTENT_TYPE_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "DJANGO_CONTENT_TYPE_TR"
BEFORE INSERT ON "DJANGO_CONTENT_TYPE"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "DJANGO_CONTENT_TYPE_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "DJANGO_CONTENT_TYPE_TR" ENABLE;
--AUTH_PERMISSION
CREATE TABLE "AUTH_PERMISSION"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"NAME" NVARCHAR2(255),
"CONTENT_TYPE_ID" NUMBER(11,0) NOT NULL ENABLE,
"CODENAME" NVARCHAR2(100),
PRIMARY KEY ("ID"),
CONSTRAINT "AUTH_PERM_CONTENT_T_01AB375A_U" UNIQUE ("CONTENT_TYPE_ID", "CODENAME"),
CONSTRAINT "AUTH_PERM_CONTENT_T_2F476E4B_F" FOREIGN KEY ("CONTENT_TYPE_ID")
REFERENCES "DJANGO_CONTENT_TYPE" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE
);
CREATE INDEX "AUTH_PERMI_CONTENT_TY_2F476E4B" ON "AUTH_PERMISSION" ("CONTENT_TYPE_ID");
CREATE SEQUENCE "AUTH_PERMISSION_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "AUTH_PERMISSION_TR"
BEFORE INSERT ON "AUTH_PERMISSION"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "AUTH_PERMISSION_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "AUTH_PERMISSION_TR" ENABLE;
--AUTH_GROUP_PERMISSION
CREATE TABLE "AUTH_GROUP_PERMISSIONS"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"GROUP_ID" NUMBER(11,0) NOT NULL ENABLE,
"PERMISSION_ID" NUMBER(11,0) NOT NULL ENABLE,
PRIMARY KEY ("ID"),
CONSTRAINT "AUTH_GROU_GROUP_ID__0CD325B0_U" UNIQUE ("GROUP_ID", "PERMISSION_ID"),
CONSTRAINT "AUTH_GROU_GROUP_ID_B120CBF9_F" FOREIGN KEY ("GROUP_ID")
REFERENCES "AUTH_GROUP" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE,
CONSTRAINT "AUTH_GROU_PERMISSIO_84C5C92E_F" FOREIGN KEY ("PERMISSION_ID")
REFERENCES "AUTH_PERMISSION" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE
);
CREATE INDEX "AUTH_GROUP_GROUP_ID_B120CBF9" ON "AUTH_GROUP_PERMISSIONS" ("GROUP_ID");
CREATE INDEX "AUTH_GROUP_PERMISSION_84C5C92E" ON "AUTH_GROUP_PERMISSIONS" ("PERMISSION_ID");
CREATE SEQUENCE "AUTH_GROUP_PERMISSIONS_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "AUTH_GROUP_PERMISSIONS_TR"
BEFORE INSERT ON "AUTH_GROUP_PERMISSIONS"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "AUTH_GROUP_PERMISSIONS_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "AUTH_GROUP_PERMISSIONS_TR" ENABLE;
--DJANGO_MIGRATIONS
CREATE TABLE "DJANGO_MIGRATIONS"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"APP" NVARCHAR2(255),
"NAME" NVARCHAR2(255),
"APPLIED" TIMESTAMP (6) NOT NULL ENABLE,
PRIMARY KEY ("ID")
);
CREATE SEQUENCE "DJANGO_MIGRATIONS_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "DJANGO_MIGRATIONS_TR"
BEFORE INSERT ON "DJANGO_MIGRATIONS"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "DJANGO_MIGRATIONS_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "DJANGO_MIGRATIONS_TR" ENABLE;
--DJANGO_SESSION
CREATE TABLE "DJANGO_SESSION"(
"SESSION_KEY" NVARCHAR2(40) NOT NULL ENABLE,
"SESSION_DATA" NCLOB,
"EXPIRE_DATE" TIMESTAMP (6) NOT NULL ENABLE,
PRIMARY KEY ("SESSION_KEY")
);
CREATE INDEX "DJANGO_SES_EXPIRE_DAT_A5C62663" ON "DJANGO_SESSION" ("EXPIRE_DATE");
--AUTH_USER
CREATE TABLE "AUTH_USER"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"PASSWORD" NVARCHAR2(128),
"LAST_LOGIN" TIMESTAMP (6),
"IS_SUPERUSER" NUMBER(1,0) NOT NULL ENABLE,
"USERNAME" NVARCHAR2(150),
"FIRST_NAME" NVARCHAR2(30),
"LAST_NAME" NVARCHAR2(150),
"EMAIL" NVARCHAR2(254),
"IS_STAFF" NUMBER(1,0) NOT NULL ENABLE,
"IS_ACTIVE" NUMBER(1,0) NOT NULL ENABLE,
"DATE_JOINED" TIMESTAMP (6) NOT NULL ENABLE,
CHECK ("IS_SUPERUSER" IN (0,1)) ENABLE,
CHECK ("IS_STAFF" IN (0,1)) ENABLE,
CHECK ("IS_ACTIVE" IN (0,1)) ENABLE,
PRIMARY KEY ("ID"),
UNIQUE ("USERNAME")
);
CREATE SEQUENCE "AUTH_USER_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "AUTH_USER_TR"
BEFORE INSERT ON "AUTH_USER"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "AUTH_USER_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "AUTH_USER_TR" ENABLE;
--DJANGO_ADMIN_LOG
CREATE TABLE "DJANGO_ADMIN_LOG"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"ACTION_TIME" TIMESTAMP (6) NOT NULL ENABLE,
"OBJECT_ID" NCLOB,
"OBJECT_REPR" NVARCHAR2(200),
"ACTION_FLAG" NUMBER(11,0) NOT NULL ENABLE,
"CHANGE_MESSAGE" NCLOB,
"CONTENT_TYPE_ID" NUMBER(11,0),
"USER_ID" NUMBER(11,0) NOT NULL ENABLE,
CHECK ("ACTION_FLAG" >= 0) ENABLE,
PRIMARY KEY ("ID"),
CONSTRAINT "DJANGO_AD_CONTENT_T_C4BCE8EB_F" FOREIGN KEY ("CONTENT_TYPE_ID")
REFERENCES "DJANGO_CONTENT_TYPE" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE,
CONSTRAINT "DJANGO_AD_USER_ID_C564EBA6_F" FOREIGN KEY ("USER_ID")
REFERENCES "AUTH_USER" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE
);
CREATE INDEX "DJANGO_ADM_CONTENT_TY_C4BCE8EB" ON "DJANGO_ADMIN_LOG" ("CONTENT_TYPE_ID");
CREATE INDEX "DJANGO_ADM_USER_ID_C564EBA6" ON "DJANGO_ADMIN_LOG" ("USER_ID");
CREATE SEQUENCE "DJANGO_ADMIN_LOG_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "DJANGO_ADMIN_LOG_TR"
BEFORE INSERT ON "DJANGO_ADMIN_LOG"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "DJANGO_ADMIN_LOG_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "DJANGO_ADMIN_LOG_TR" ENABLE;
--AUTH_USER_GROUPS
CREATE TABLE "AUTH_USER_GROUPS"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"USER_ID" NUMBER(11,0) NOT NULL ENABLE,
"GROUP_ID" NUMBER(11,0) NOT NULL ENABLE,
PRIMARY KEY ("ID"),
CONSTRAINT "AUTH_USER_USER_ID_G_94350C0C_U" UNIQUE ("USER_ID", "GROUP_ID"),
CONSTRAINT "AUTH_USER_USER_ID_6A12ED8B_F" FOREIGN KEY ("USER_ID")
REFERENCES "AUTH_USER" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE,
CONSTRAINT "AUTH_USER_GROUP_ID_97559544_F" FOREIGN KEY ("GROUP_ID")
REFERENCES "AUTH_GROUP" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE
);
CREATE INDEX "AUTH_USER__USER_ID_6A12ED8B" ON "AUTH_USER_GROUPS" ("USER_ID");
CREATE INDEX "AUTH_USER__GROUP_ID_97559544" ON "AUTH_USER_GROUPS" ("GROUP_ID");
CREATE SEQUENCE "AUTH_USER_GROUPS_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "AUTH_USER_GROUPS_TR"
BEFORE INSERT ON "AUTH_USER_GROUPS"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "AUTH_USER_GROUPS_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "AUTH_USER_GROUPS_TR" ENABLE;
--AUTH_USER_USER_PERMISSIONS
CREATE TABLE "AUTH_USER_USER_PERMISSIONS"(
"ID" NUMBER(11,0) NOT NULL ENABLE,
"USER_ID" NUMBER(11,0) NOT NULL ENABLE,
"PERMISSION_ID" NUMBER(11,0) NOT NULL ENABLE,
PRIMARY KEY ("ID"),
CONSTRAINT "AUTH_USER_USER_ID_P_14A6B632_U" UNIQUE ("USER_ID", "PERMISSION_ID"),
CONSTRAINT "AUTH_USER_USER_ID_A95EAD1B_F" FOREIGN KEY ("USER_ID")
REFERENCES "AUTH_USER" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE,
CONSTRAINT "AUTH_USER_PERMISSIO_1FBB5F2C_F" FOREIGN KEY ("PERMISSION_ID")
REFERENCES "AUTH_PERMISSION" ("ID") DEFERRABLE INITIALLY DEFERRED ENABLE
);
CREATE INDEX "AUTH_USER__USER_ID_A95EAD1B" ON "AUTH_USER_USER_PERMISSIONS" ("USER_ID");
CREATE INDEX "AUTH_USER__PERMISSION_1FBB5F2C" ON "AUTH_USER_USER_PERMISSIONS" ("PERMISSION_ID");
CREATE SEQUENCE "AUTH_USER_USER_PERMISSIONS_SEQ"
MINVALUE 1
MAXVALUE 999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
CREATE OR REPLACE TRIGGER "AUTH_USER_USER_PERMISSIONS_TR"
BEFORE INSERT ON "AUTH_USER_USER_PERMISSIONS"
FOR EACH ROW
WHEN (new."ID" IS NULL) BEGIN
SELECT "AUTH_USER_USER_PERMISSIONS_SEQ".nextval
INTO :new."ID" FROM dual;
END;
ALTER TRIGGER "AUTH_USER_USER_PERMISSIONS_TR" ENABLE;
Django 2.X, Oracle11gํ๊ฒฝ์์ ์์ ์คํค๋ง๋ฅผ ์ ์ฉํด์ฃผ๊ณ ์๋ฒ๋ฅผ ์คํํด์ค๋ค๋ฉด admin์ ๋ฐ๋ก ์ ๊ทผํด์ ์ฌ์ฉํ ์ ์๋ค.
์ฃผ์์ฌ์ฉ
๋จ, ์ฌ์ ํ Django 2.X๋ฒ์ ์์๋ Oracle11g๋ฅผ ์ง์ํ์ง ์๊ธฐ ๋๋ฌธ์ manage.py์์ ์ฌ์ฉ๋๋ migrate์ ๊ฐ์ ๋ช ๋ น์ ์ฌ์ฉํ ์ ์๋ค. ํ๋ก์ ํธ๋ฅผ ๋ฐฐํฌํด์ ์ฌ์ฉํ ์๋ ์์ง๋ง... Django์์ ์ ๊ณตํ๋ ๋ช ๋ น๋ค์ ์ฌ์ฉํ์ง ๋ชปํ๋ค.
๋๊ธ