# Student Management System A terminal CRUD application for managing **Students**, **Guardians**, and **Attendance** records, backed by MySQL. Built against the schema in Tables 9.3–9.5 (STUDENT, GUARDIAN, ATTENDANCE). ## What it does on startup 1. Connects to the MySQL server at `10.10.0.160:3306`. 2. Verifies the `student_db` database exists — creates it if not. 3. Verifies the `GUARDIAN`, `STUDENT`, and `ATTENDANCE` tables exist (in that order, since STUDENT references GUARDIAN and ATTENDANCE references STUDENT) — creates any that are missing, with the exact data types and constraints from the schema (primary keys, foreign keys, `NOT NULL`, `UNIQUE` on `GPhone`, and the composite primary key `(AttendanceDate, RollNumber)` on ATTENDANCE). 4. Launches an interactive menu for Create / Read / Update / Delete. ## Setup 1. Install the one dependency: ```bash pip install -r requirements.txt ``` 2. Set your MySQL credentials as environment variables (the host/port/ database default to the assignment's values already): ```bash export DB_USER=root export DB_PASSWORD=your_password_here # optional overrides — these already default correctly: # export DB_HOST=10.10.0.160 # export DB_PORT=3306 # export DB_NAME=student_db ``` 3. Run it: ```bash python3 main.py ``` ## Files | File | Purpose | |-----------------|------------------------------------------------------------------| | `config.py` | Connection settings (reads env vars, falls back to defaults) | | `db.py` | Connects to MySQL; verifies/creates the database and tables | | `crud.py` | All Create/Read/Update/Delete operations for the three tables | | `ui_helpers.py` | Input prompts/validation and table-printing for the terminal | | `main.py` | The menu-driven application — run this | ## Using the app The main menu has three sections: - **Guardian management** — list, view, add, update, delete guardians. GUID must be a 12-digit number (per the Aadhaar-number schema note); phone, if given, must be 10 digits and is unique across guardians. - **Student management** — list, view, add, update, delete students. Roll number is up to 3 digits; each student must reference an existing guardian's GUID (add the guardian first). - **Attendance management** — mark attendance (P/A) for a student on a date (marking the same student+date again updates it instead of erroring), view attendance by date or by student, and delete records. Deleting a guardian who still has students is blocked by the foreign key (delete or reassign their students first). Deleting a student cascades and removes their attendance records automatically. ## Notes - Uses [mysql-connector-python](https://dev.mysql.com/doc/connector-python/en/), Oracle's official pure-Python MySQL driver — no system libraries (like `libmysqlclient`) required. - All input is validated against the schema's constraints (max lengths, digit counts, date format, P/A status) before hitting the database, and database-level errors (duplicate keys, foreign key violations) are caught and shown as friendly messages rather than crashing. - Tested end-to-end (connect → create DB/tables → full CRUD → constraint error handling → cascade delete) against a local MySQL/MariaDB instance before delivery.