2100_01_01_175526_add_references.php 686 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. use Illuminate\Support\Facades\Schema;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Database\Migrations\Migration;
  5. class AddReferences extends Migration
  6. {
  7. /**
  8. * 外键约束
  9. */
  10. public function up()
  11. {
  12. Schema::table('user_infos', function (Blueprint $table) {
  13. // 联动删除
  14. $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
  15. });
  16. }
  17. /**
  18. * Reverse the migrations.
  19. *
  20. * @return void
  21. */
  22. public function down()
  23. {
  24. Schema::table('user_infos', function (Blueprint $table) {
  25. $table->dropForeign(['user_id']);
  26. });
  27. }
  28. }