0

If I run this in my migration up method, what do I put in the down method?

$table->foreignIdFor(MyClass::class)->nullable()->constrained();

Thanks!

1
  • The down method should contain whatever is needed to undo whatever the up method did.
    – ryantxr
    Commented Nov 18, 2022 at 6:46

1 Answer 1

1

In the down method you should drop the foreign key:

$table->dropForeign(['column_name']);
$table->dropColumn(['column_name']);
2
  • Thanks! And what about the index and the actual column? I need 3 different actions?
    – SeaBass
    Commented Nov 18, 2022 at 7:12
  • You are right, the column should also be dropped. Edited my answer. You actually need only two actions - first to drop the foreign index, and then to drop the column itself. Commented Nov 18, 2022 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.