0

i have a User and a Device Table. If a User connects to a Device, the Device will know its User (Foreign Key). A Device can only have one User.
I create a Foreign Key with

userToDevice.foreignKeyDeclaration.constrainReference(onDelete cascade)

it does alter the table like that

alter table Device add constraint DeviceFK10 foreign key (user_id) references User(id) on delete cascade;

Now, when i create a User, assign it to a Device and then delete the User, the user_id property at Device Table doesn't get deleted, too.

//CREATE DEVICE
val device = queries.deviceCreate("XYZ-Device", None) //None User

//ASSIGN USER TO DEVICE
update(deviceT)(d=> where(d.id === device.get.id) set(d.user_id := user.id))

//DELETE USER
userTable.deleteWhere(u=> u.id === user.id)

Why is it that it doesn't delete the Foreign Key even with on delete cascade?

EDIT:
I think i messed anything up with the relation.
Here you can see example code. Probably you can tell me what i am doing wrong here.
ShowCase on Github

EDIT2:
It seems like mysql doesn't even create the Foreign Key. I can't find any when i check localhost/phpmyadmin

B. Kemmer
  • 1,517
  • 1
  • 14
  • 32
  • Sounds like you are having an issue with mysql here since the cascade is declared at the DB level. Can you also post your table definition? Also, how are you executing your schema updates (ie, how did that `alter table` command get executed)? Were there any errors? – jcern Nov 18 '14 at 13:44
  • No errors at all. Everything succeeded without errors. You can actually check my table definition within my ShowCase project, which i have posted on GitHub (You can find it after my first Edit). – B. Kemmer Nov 18 '14 at 13:59

1 Answers1

2

I think the default table type for MySQL is MyISAM, which doesn't support foreign keys.

Dave Whittaker
  • 3,102
  • 13
  • 14
  • Oh Thanks for that hint. I need to use `MySQLInnoDBAdapter` instead of `MySQLAdapter`. http://squeryl.org/api/index.html#org.squeryl.adapters.MySQLInnoDBAdapter – B. Kemmer Nov 18 '14 at 14:06