laravel/laravel — Issue #395: Can't specify ON UPDATE or ON DELETE when adding foreign keys in Schema?
Author: cviebrock
Created: 2012-03-08 18:19:33+00:00
State: open

My understanding of the new foreign key support in the schema builder is that code like this:

```php
foreign('user_id', 'fk_actions_users')->on('users')->references('id');
});
```

would run a query like this:

```sql
ALTER TABLE actions
ADD CONSTRAINT fk_actions_users
FOREIGN KEY (user_id)
REFERENCES users(id);
```

However, I don't see anyway to build a schema command to generate

```sql
ALTER TABLE actions
ADD CONSTRAINT fk_actions_users
FOREIGN KEY (user_id)
REFERENCES users(id)
ON UPDATE CASCADE
ON DELETE CASCADE;
```

And (in MySQL at least) there doesn't seem to be a way to add the referential actions after-the-fact, via `ALTER TABLE`. They can only be defined when creating the foreign key.

Can we add something to the schema builder to allow this? Maybe:

```php
foreign('user_id', 'fk_actions_users')->on('users')->references('id')->referential_actions(array(
'update' => 'cascade',
'delete' => 'cascade'
));
});
```