Posts

Showing posts with the label foreign-keys

Creating MariaDB table with a foreignkey to varchar

Creating MariaDB table with a foreignkey to varchar I am trying to create a table (yTable) which has a foreign key mapped to another table (xTable). I am using MariaDB. When I try to create it I get this error: Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint. When i dump existing table it gives me this description: CREATE TABLE `xTable` ( `id` varchar(25) NOT NULL, ... PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), ... The query that I try to use to create another table is: Create table `yTable` ( `xTable_id` varchar(25) NOT NULL, Primary Key (`xTable_id`), Foreign Key (`xTable_id`) references `xTable` (`id`) on delete cascade on update cascade); In both pasted queries I have removed some columns. They don't affect anything. The problem is with connecting the xTable_id from yTable to xTable.id. For some reason it doesn't...

How to implement prerequisite table in MySQL

How to implement prerequisite table in MySQL I'm using Laravel and I've a table in database called 'course'. It has some fields like 'title', 'content' and etc... And also I want a course has some prerequisites (other courses). How can I implement this? I can do this by self reference foreign key but in this way there will be just one prerequisite for a course. I think your answer is in the title - create and implement a prerequisite table. – P.Salmon Jul 1 at 11:47 @P.Salmon yes, you are right :) – Saman Sattari Jul 2 at 15:12 2 Answers 2 As a Course ca...