Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP / MySQL - Foreign Key Issue

Tags:

php

mysql

Im following a tutorial at the moment and learning how to build something into my existing site.

The tutorial tells me that i need to run this against my database

ALTER TABLE posts ADD FOREIGN KEY(post_by) REFERENCES users(user_id) ON DELETE RESTRICT ON UPDATE CASCADE;

and im receiving an error saying it cant create table.

the 'users' table is from my existing database and everything else is new.

The tutorial gives me a few alter commands to run and they all go perfect, except when im trying to use the 'users' table.

Im totally stuck on this, any help would be greatly appreciated.

Cheers


1 Answers

Check your table type. It should be InnoDB.

like image 50
SaidbakR Avatar answered Sep 03 '26 14:09

SaidbakR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!