Skip to content

Commit c08cf38

Browse files
committed
Remove and then recreate foreign key constraint
1 parent aec3479 commit c08cf38

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

app/sprinkles/account/src/Database/Migrations/v430/UpdateUsersTable.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public function up()
3737
{
3838
if ($this->schema->hasTable('users')) {
3939
$this->schema->table('users', function (Blueprint $table) {
40+
$table->dropForeign('users_group_id_foreign');
4041
$table->integer('group_id')->unsigned()->default(null)->comment('The id of the user group.')->nullable()->change();
42+
$table->foreign('group_id')->references('id')->on('groups');
4143
});
4244
}
4345
}
@@ -48,7 +50,9 @@ public function up()
4850
public function down()
4951
{
5052
$this->schema->table('users', function (Blueprint $table) {
53+
$table->dropForeign('users_group_id_foreign');
5154
$table->integer('group_id')->unsigned()->default(1)->comment('The id of the user group.')->nullable(false)->change();
55+
$table->foreign('group_id')->references('id')->on('groups');
5256
});
5357
}
5458
}

0 commit comments

Comments
 (0)