-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_db.py
More file actions
20 lines (16 loc) · 927 Bytes
/
create_db.py
File metadata and controls
20 lines (16 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from app import app, db, Course # Import 'app', 'db', and 'Course' from app.py
# Create an application context
with app.app_context():
# Initialize the database and create tables
db.create_all()
# Prepopulate the course table with the provided data
courses = [
Course(course_code="CSE01", course_name="MAD I", course_description="Modern Application Development - I"),
Course(course_code="CSE02", course_name="DBMS", course_description="Database management Systems"),
Course(course_code="CSE03", course_name="PDSA", course_description="Programming, Data Structures and Algorithms using Python"),
Course(course_code="BST13", course_name="BDM", course_description="Business Data Management")
]
# Add courses to the session and commit
db.session.bulk_save_objects(courses)
db.session.commit()
print("Database created with tables and course data populated.")