|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
|
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
6
|
|
|
|
|
7
|
|
|
class CreateForeignKey extends Migration |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Run the migrations. |
|
11
|
|
|
* |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
|
|
public function up() |
|
15
|
|
|
{ |
|
16
|
|
|
Schema::table('transition_states', function(Blueprint $table){ |
|
17
|
|
|
$table->foreign('history_id') |
|
18
|
|
|
->references('id') |
|
19
|
|
|
->on('histories') |
|
20
|
|
|
->onDelete('set null') |
|
21
|
|
|
->onUpdate('restrict'); |
|
22
|
|
|
}); |
|
23
|
|
|
Schema::table('histories', function(Blueprint $table){ |
|
24
|
|
|
$table->foreign('workflow_id') |
|
25
|
|
|
->references('id') |
|
26
|
|
|
->on('workflows') |
|
27
|
|
|
->onDelete('set null') |
|
28
|
|
|
->onUpdate('restrict'); |
|
29
|
|
|
}); |
|
30
|
|
|
Schema::table('histories', function(Blueprint $table){ |
|
31
|
|
|
$table->foreign('workflow_transition_id') |
|
32
|
|
|
->references('id') |
|
33
|
|
|
->on('workflow_transition') |
|
34
|
|
|
->onDelete('set null') |
|
35
|
|
|
->onUpdate('restrict'); |
|
36
|
|
|
}); |
|
37
|
|
|
Schema::table('workflow_transition', function(Blueprint $table){ |
|
38
|
|
|
$table->foreign('workflow_id') |
|
39
|
|
|
->references('id') |
|
40
|
|
|
->on('workflows') |
|
41
|
|
|
->onDelete('set null') |
|
42
|
|
|
->onUpdate('restrict'); |
|
43
|
|
|
}); |
|
44
|
|
|
Schema::table('workflow_state', function(Blueprint $table){ |
|
45
|
|
|
$table->foreign('workflow_id') |
|
46
|
|
|
->references('id') |
|
47
|
|
|
->on('workflows') |
|
48
|
|
|
->onDelete('set null') |
|
49
|
|
|
->onUpdate('restrict'); |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Reverse the migrations. |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
public function down() |
|
60
|
|
|
{ |
|
61
|
|
|
Schema::table('transition_states', function(Blueprint $table) { |
|
62
|
|
|
$table->dropForeign('transition_states_history_id_foreign'); |
|
63
|
|
|
}); |
|
64
|
|
|
Schema::table('histories', function(Blueprint $table) { |
|
65
|
|
|
$table->dropForeign('histories_workflow_id_foreign'); |
|
66
|
|
|
}); |
|
67
|
|
|
Schema::table('histories', function(Blueprint $table) { |
|
68
|
|
|
$table->dropForeign('histories_workflow_transition_id_foreign'); |
|
69
|
|
|
}); |
|
70
|
|
|
Schema::table('workflow_state', function(Blueprint $table) { |
|
71
|
|
|
$table->dropForeign('workflow_state_workflow_id_foreign'); |
|
72
|
|
|
}); |
|
73
|
|
|
Schema::table('workflow_transition', function(Blueprint $table) { |
|
74
|
|
|
$table->dropForeign('workflow_transition_workflow_id_foreign'); |
|
75
|
|
|
}); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.