-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDataBase.py
39 lines (33 loc) · 970 Bytes
/
createDataBase.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
import psycopg2
from config import *
def create_tables():
#""" create tables in the PostgreSQL database"""
commands = (
"""
CREATE TABLE photos_instagram (
id VARCHAR(20) ,
path VARCHAR(50),
status VARCHAR(15),
owner VARCHAR(50)
)
""")
conn = None
try:
# connect to the PostgreSQL server
conn = psycopg2.connect(
database=databaseName, user=db_user, password=passwordDataBase, host='127.0.0.1', port= '5432'
)
cur = conn.cursor()
# create table one by one
cur.execute(commands)
# close communication with the PostgreSQL database server
cur.close()
# commit the changes
conn.commit()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
if __name__ == '__main__':
create_tables()