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 :: laravel check if get is empty 
Php :: php text colors 
Php :: php remove bom 
Php :: php add string inside string at position 
Php :: get domain from subdomain php 
Php :: decode jwt token laravel 
Php :: laravel eloquent increment 
Php :: regex to check date format php 
Php :: php grab year from date 
Php :: laravel created_at migration 
Php :: increase xampp phpmyadmin import limit 
Php :: unique validation on update laravel 
Php :: email validation in laravel 
Php :: carbon set locale laravel 
Php :: laravel check if form has errors 
Php :: php check if string email 
Php :: doctrine php driver execption 
Php :: sum multiple fields separately in laravel 
Php :: php sum array elements 
Php :: return json response id name from eloquent all laravel 
Php :: where date laravel 
Php :: first letter capital of every word in php 
Php :: Replicating claims as headers is deprecated and will removed from v4.0. Please manually set the header if you need it replicated.", 
Php :: form_dropdown codeigniter from database is assocative array 
Php :: convert multidimensional array into single dimension php 
Php :: php 7 count result in database 
Php :: php change an associative array into indexed array 
Php :: date add one day php 
Php :: wordpress disable posts 
Php :: how to forget session in laravel 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =