DekGenius.com
PHP
make a forign key in migrations using laravel 8
$table -> unsignedBigInteger ( 'user_id' ) ;
$table -> foreign ( 'user_id' ) -> references ( 'id' ) -> on ( 'users' ) -> onDelete ( 'cascade' ) ;
laravel foreign key
Schema:: table ( 'posts' , function ( Blueprint $table ) {
$table -> unsignedBigInteger ( 'user_id' ) ;
$table -> foreign ( 'user_id' ) -> references ( 'id' ) -> on ( 'users' ) ;
} ) ;
OR
Schema:: table ( 'posts' , function ( Blueprint $table ) {
$table -> foreignId ( 'user_id' ) -> constrained ( ) ;
} ) ;
foreign key in Laravel
$table -> foreignId ( 'user_id' ) -> constrained ( ) -> onDelete ( 'cascade' ) ;
add foreign key column laravel 5.8
update your `integer('user_id')` to `bigInteger('user_id')`
public function up ( ) {
Schema:: create ( 'evaluation' , function ( Blueprint $table ) {
$table -> increments ( 'id' ) ;
$table -> bigInteger ( 'user_id' ) -> unsigned ( ) -> index ( ) ;
$table -> timestamps ( ) ;
$table -> foreign ( 'user_id' ) -> references ( 'id' ) -> on ( 'users' ) -> onDelete ( 'cascade' ) ;
} ) ;
}
laravel foreign key constraint
public function up ( )
{
Schema:: create ( 'replies' , function ( Blueprint $table ) {
$table -> bigIncrements ( 'id' ) ;
$table -> text ( 'body' ) ;
$table -> unsignedBigInteger ( 'question_id' ) ;
$table -> integer ( 'user_id' ) -> unsigned ( ) ;
$table -> foreign ( 'question_id' ) -> references ( 'id' ) -> on ( 'questions' ) -> onDelete ( 'cascade' ) ;
$table -> timestamps ( ) ;
} ) ;
}
create foreign key laravel migration
Schema:: table ( 'posts' , function ( Blueprint $table ) {
$table -> unsignedBigInteger ( 'user_id' ) ;
$table -> foreign ( 'user_id' ) -> references ( 'id' ) -> on ( 'users' ) ;
} ) ;
laravel 8 foreign key migration
use IlluminateDatabaseSchemaBlueprint ;
use IlluminateSupportFacadesSchema ;
Schema:: table ( 'posts' , function ( Blueprint $table ) {
$table -> unsignedBigInteger ( 'user_id' ) ;
$table -> foreign ( 'user_id' ) -> references ( 'id' ) -> on ( 'users' ) ;
} ) ;
laravel foreign key
Schema:: table ( 'posts' , function ( Blueprint $table ) {
$table -> foreignId ( 'user_id' ) -> constrained ( ) ;
} ) ;
$table -> foreignId ( 'user_id' ) -> constrained ( 'users' ) ;
$table -> foreignId ( 'user_id' )
-> constrained ( )
-> onUpdate ( 'cascade' )
-> onDelete ( 'cascade' ) ;
foreign key laravel migration
$table -> foreign ( 'column_name' ) -> references ( 'id' ) -> on ( 'table_name' ) -> onDelete ( 'cascade' ) ;
add foreign key in laravel migration
$table -> foreign ( 'user_id' ) -> references ( 'id' ) -> on ( 'users' ) -> onDelete ( 'cascade' ) ;
laravel 8 foreign key
Schema:: table ( 'posts' , function ( Blueprint $table ) {
$table -> foreignId ( 'user_id' ) -> constrained ( ) ;
} ) ;
Laravel adding Foreign Key Constraints
$table -> foreignId ( 'user_id' )
-> constrained ( "users" ) < -
-> onUpdate ( 'cascade' )
-> onDelete ( 'cascade' ) ;
laravel foreign key
$table -> foreignId ( 'user_id' )
-> constrained ( )
-> onUpdate ( 'cascade' )
-> onDelete ( 'cascade' ) ;
Laravel create foreign key column in migration
$table -> foreignId ( 'post_id' )
-> constrained ( )
-> onUpdate ( 'cascade' )
-> onDelete ( 'cascade' ) ;
Laravel migrations custom foreign key
$table -> unsignedBigInteger ( 'created_by' ) ;
$table -> foreign ( 'created_by' ) -> references ( 'id' ) -> on ( 'users' ) ;
How to create foreign key in Laravel
$table -> foreign ( 'category_id' ) -> references ( 'id' ) -> on ( 'categories' ) -> onUpdate ( 'cascade' ) -> onDelete ( 'cascade' ) ;
© 2022 Copyright:
DekGenius.com