How to remove unique constraint from a column using Laravel migrations?
Hi Guys,
In this example,I will learn you how to remove unique constraint from a column using laravel migrations.you can easy and simply remove unique constraint from a column using laravel migrations.
I have to remove a unique constraint from an email column using Laravel Migrations. Here is my code.I required doctrine/dbal in composer.json is it necessary to use it in migration files too or it will be called automatically.
Example 1:
class AlterEmailToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('email')->unique(false)->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->string('email')->nullable(false)->unique()->change();
});
}
Example 2:
$table->dropUnique('tableName_columnName_unique');
class AlterEmailToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->dropUnique('users_email_unique');
});
}
It will help you...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial