-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_table.py
51 lines (41 loc) · 1.56 KB
/
create_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pymysql
from db_helper import DB_Helper
class Create_Table():
def query_create(self):
TABLES = {}
result = DB_Helper()
TABLES['tables'] = (
"CREATE TABLE `tables`("
" `g_id` int NOT NULL AUTO_INCREMENT,"
" `title` VARCHAR (50),"
"PRIMARY KEY (`g_id`)"
")ENGINE=InnoDB")
TABLES['community'] = (
"CREATE TABLE `community`("
" `c_id` int NOT NULL AUTO_INCREMENT,"
" `community_title` VARCHAR (50),"
" `url` VARCHAR (255),"
" `g_id` int NOT NULL,"
" FOREIGN KEY (`g_id`) REFERENCES tables(`g_id`),"
"PRIMARY KEY (`c_id`)"
")ENGINE=InnoDB")
TABLES['users'] = (
"CREATE TABLE `users`("
" `u_id` int NOT NULL AUTO_INCREMENT,"
" `url` VARCHAR (255),"
"PRIMARY KEY (`u_id`)"
")ENGINE=InnoDB")
TABLES['sub_community'] = (
"CREATE TABLE `sub_community`("
" `s_id` int NOT NULL AUTO_INCREMENT,"
" `community` VARCHAR (50),"
" `title` VARCHAR (50),"
" `url` VARCHAR (255),"
" `text` VARCHAR (255),"
" `u_id` int,"
" FOREIGN KEY (`u_id`) REFERENCES users(`u_id`),"
" `c_id` int,"
" FOREIGN KEY (`c_id`) REFERENCES community(`c_id`),"
"PRIMARY KEY (`s_id`)"
")ENGINE=InnoDB")
result.create_table(TABLES)