Add try/catch in migration in case foreign key doesn't exist

This commit is contained in:
Hillel Coren 2017-05-07 17:59:43 +03:00
parent 9168372f4d
commit 123068591b

View File

@ -22,6 +22,8 @@ class AddCustomContactFields extends Migration
$table->string('custom_value2')->nullable();
});
// This may fail if the foreign key doesn't exist
try {
Schema::table('payment_methods', function ($table) {
$table->unsignedInteger('account_gateway_token_id')->nullable()->change();
$table->dropForeign('payment_methods_account_gateway_token_id_foreign');
@ -38,6 +40,9 @@ class AddCustomContactFields extends Migration
Schema::table('payments', function ($table) {
$table->foreign('payment_method_id')->references('id')->on('payment_methods')->onDelete('cascade');
});
} catch (Exception $e) {
// do nothing
}
Schema::table('expenses', function($table) {
$table->unsignedInteger('payment_type_id')->nullable();