From b92f5bc854267fedf918f1923a4b7d2d1192bfba Mon Sep 17 00:00:00 2001 From: Tobsn Date: Tue, 21 Aug 2012 00:09:01 +0200 Subject: [PATCH 1/3] Docu on how to ensure foreign() works tons of people are doing it wrong every day - this should fix it or at least can be used as reference. --- laravel/documentation/database/schema.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/laravel/documentation/database/schema.md b/laravel/documentation/database/schema.md index 605f53d0..ff25ab65 100644 --- a/laravel/documentation/database/schema.md +++ b/laravel/documentation/database/schema.md @@ -144,4 +144,10 @@ ## Foreign Keys You may also easily drop a foreign key constraint. The default foreign key names follow the [same convention](#dropping-indexes) as the other indexes created by the Schema builder. Here's an example: - $table->drop_foreign('posts_user_id_foreign'); \ No newline at end of file + $table->drop_foreign('posts_user_id_foreign'); + +> **Note:** The field referenced in the foreign key is very likely an auto increment and therefore automatically an unsigned integer. Please make sure to create the foreign key field with **unsigned()** as both fields have to be the exact same type, the engine on both tables has to be set to **InnoDB**, and the referenced table must be created **before** the table with the foreign key. + + $table->engine = 'InnoDB'; + + $table->integer('user_id')->unsigned(); \ No newline at end of file From 546c96261254373b7b366ce294aeba56636611c6 Mon Sep 17 00:00:00 2001 From: Tobsn Date: Tue, 21 Aug 2012 00:10:03 +0200 Subject: [PATCH 2/3] Revert "Docu on how to ensure foreign() works" This reverts commit b92f5bc854267fedf918f1923a4b7d2d1192bfba. --- laravel/documentation/database/schema.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/laravel/documentation/database/schema.md b/laravel/documentation/database/schema.md index ff25ab65..605f53d0 100644 --- a/laravel/documentation/database/schema.md +++ b/laravel/documentation/database/schema.md @@ -144,10 +144,4 @@ ## Foreign Keys You may also easily drop a foreign key constraint. The default foreign key names follow the [same convention](#dropping-indexes) as the other indexes created by the Schema builder. Here's an example: - $table->drop_foreign('posts_user_id_foreign'); - -> **Note:** The field referenced in the foreign key is very likely an auto increment and therefore automatically an unsigned integer. Please make sure to create the foreign key field with **unsigned()** as both fields have to be the exact same type, the engine on both tables has to be set to **InnoDB**, and the referenced table must be created **before** the table with the foreign key. - - $table->engine = 'InnoDB'; - - $table->integer('user_id')->unsigned(); \ No newline at end of file + $table->drop_foreign('posts_user_id_foreign'); \ No newline at end of file From 161ae3f6e6758fa249fe022fca4059176042b478 Mon Sep 17 00:00:00 2001 From: Tobsn Date: Tue, 21 Aug 2012 00:12:29 +0200 Subject: [PATCH 3/3] Docu on how to ensure foreign() works tons of people are doing it wrong every day - this should fix it or at least can be used as reference. --- laravel/documentation/database/schema.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/laravel/documentation/database/schema.md b/laravel/documentation/database/schema.md index 605f53d0..ff25ab65 100644 --- a/laravel/documentation/database/schema.md +++ b/laravel/documentation/database/schema.md @@ -144,4 +144,10 @@ ## Foreign Keys You may also easily drop a foreign key constraint. The default foreign key names follow the [same convention](#dropping-indexes) as the other indexes created by the Schema builder. Here's an example: - $table->drop_foreign('posts_user_id_foreign'); \ No newline at end of file + $table->drop_foreign('posts_user_id_foreign'); + +> **Note:** The field referenced in the foreign key is very likely an auto increment and therefore automatically an unsigned integer. Please make sure to create the foreign key field with **unsigned()** as both fields have to be the exact same type, the engine on both tables has to be set to **InnoDB**, and the referenced table must be created **before** the table with the foreign key. + + $table->engine = 'InnoDB'; + + $table->integer('user_id')->unsigned(); \ No newline at end of file