From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Adding foreign keys for course in messages

Adding foreign keys for course in messages

Hello and welcome. In this session, as part of our Next.js project, we will extend our messaging system by linking each message to a specific course using foreign keys in the database. This enhancement is the first crucial step towards creating course-specific chatrooms in a future session. By implementing this, users will eventually be able to post and view messages related only to a particular course, making discussions much more organized and relevant. Let's get started inside create-tables.sql, located in the schema folder. Now I am adding a new column to our messages table to link each message to a course. I'm adding a column named course underscore ID of type integer with a not null constraint right after the user ID. This course ID column will store the ID of the course that the message belongs to. I've chosen the integer data type because it will hold a number that corresponds to the ID of a course in our courses table. The not null constraint is very important here. It's a…

Contents