Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel migration remove unique constraint

/** To drop an index you must specify the index's name. 
Laravel assigns a reasonable name to the indexes by default. 
Simply concatenate the table name, the names of the column in the index, 
and the index type **/

// Format of unique key tableName_column_unique
$table->dropUnique('users_email_unique');
Comment

laravel migration remove unique constraint

// There are two ways to handle this:

// 1.	You can simply pass the column name wrapped in an array
//		and let laravel sort out the rest:
Schema::table('users', function (Blueprint $table) {
  $table->dropUnique(['email']);
  // $table->dropIndex(['email']); --> this pattern also works for other constraints/indexes like this
});

// 2.	You can remember the way laravel formats index names ([TABLE_NAME]_[COLUMN_NAME]_unique),
// 		and pass that as a string:
Schema::table('users', function (Blueprint $table) {
	$table->dropUnique('users_email_unique');
});
Comment

laravel migration remove unique

//The UNique need be a constraint name
// This name has this format:
// [TABLE_NAME]_[COLUMN_NAME]_unique
// For 'users' table and 'user_code' column, whe get the name:
// users_user_code_unique
$table->dropUnique('users_user_code_unique');

//The inverst is 
$table->unique('user_code');
Comment

PREVIOUS NEXT
Code Example
Php :: how match array in laravel collection 
Php :: eliminar ultimo caracter string php 
Php :: explode in php 
Php :: laravel group by on subquery 
Php :: acf gallery 
Php :: php include files 
Php :: laravel check record exists 
Php :: phpmailer send attachment 
Php :: php contains substring 
Php :: Array and string offset access syntax with curly braces is deprecated in tcpdf.php 
Php :: How to pass JavaScript variables to PHP? 
Php :: laravel query builder sum 
Php :: explode in laravel blade 
Php :: password required wp 
Php :: laravel websockets onmessage 
Php :: How to display image from aws s3 in laravel blade 
Php :: save array in mysql php 
Php :: carbon parse timestamp 
Php :: delete image s3 laravel 
Php :: php artisan storage link cpanel 
Php :: laravel with has 
Php :: php explode multiple delimiters 
Php :: php curl example 
Php :: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) 
Php :: php array merge skip diplicate 
Php :: laravel hasmany count 
Php :: sum of columns laravel eloquent 
Php :: php remove array element reset keys 
Php :: how to bulk insert array into sql php 
Php :: get values from text file php 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =