diff --git a/database/migrations/2026_03_06_163831_alter_position_authority_logs_nullable_user_position_id.php b/database/migrations/2026_03_06_163831_alter_position_authority_logs_nullable_user_position_id.php new file mode 100644 index 0000000..6f54a74 --- /dev/null +++ b/database/migrations/2026_03_06_163831_alter_position_authority_logs_nullable_user_position_id.php @@ -0,0 +1,59 @@ +dropForeign(['user_position_id']); + + $table->unsignedBigInteger('user_position_id') + ->nullable() + ->change(); + + $table->foreign('user_position_id') + ->references('id') + ->on('user_positions') + ->nullOnDelete(); + }); + } + + /** + * 回滚:恢复为 NOT NULL(需确保数据中无 null 值) + */ + public function down(): void + { + Schema::table('position_authority_logs', function (Blueprint $table) { + $table->dropForeign(['user_position_id']); + + $table->unsignedBigInteger('user_position_id') + ->nullable(false) + ->change(); + + $table->foreign('user_position_id') + ->references('id') + ->on('user_positions') + ->cascadeOnDelete(); + }); + } +};