diff --git a/database.md b/database.md index d295dd0526f..119ee414833 100644 --- a/database.md +++ b/database.md @@ -34,6 +34,15 @@ After creating a new SQLite database using a command such as `touch database/dat DB_CONNECTION=sqlite DB_DATABASE=/absolute/path/to/database.sqlite +To enable foreign key constraints for your SQLite connections, you can add the `foreign_key_constraints` option to `config/database.php` like this: + + 'sqlite' => [ + 'driver' => 'sqlite', + 'database' => env('DB_DATABASE', database_path('database.sqlite')), + 'prefix' => '', + 'foreign_key_constraints' => true, + ], + ### Read & Write Connections diff --git a/migrations.md b/migrations.md index d82d14c62b1..507a6316896 100644 --- a/migrations.md +++ b/migrations.md @@ -454,7 +454,7 @@ You may also specify the desired action for the "on delete" and "on update" prop ->references('id')->on('users') ->onDelete('cascade'); -To drop a foreign key, you may use the `dropForeign` method. Foreign key constraints use the same naming convention as indexes. So, we will concatenate the table name and the columns in the constraint then suffix the name with "_foreign": +To drop a foreign key, you may use the `dropForeign` method. Foreign key constraints use the same naming convention as indexes. So, we will concatenate the table name and the columns in the constraint then suffix the name with "\_foreign": $table->dropForeign('posts_user_id_foreign'); @@ -468,4 +468,4 @@ You may enable or disable foreign key constraints within your migrations by usin Schema::disableForeignKeyConstraints(); -> {note} SQLite disables foreign key constraints by default. When using SQLite, make sure to enable foreign key support before attempting to create them in your migrations. +> {note} SQLite disables foreign key constraints by default. When using SQLite, make sure to [enable foreign key support](/docs/{{version}}/database#configuration) in your database configuration before attempting to create them in your migrations.