Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daniel21gt's avatar

Problems to modify table attribute in migrations, laravel 5.5

How are you.

I know that to alter changes in existing migrations, this command can be applied.

php artisan make: migration users

But in my case, I have a table users with a field called mail, which has an attribute like UNIQUE (), how can I change this attribute, without altering the information I have in the tables?

0 likes
6 replies
DavidPetrov's avatar

Execute the command php artisan make:migration alter_email_on_users_table --table=users

Then a migration will be loaded with your table already set up. Inside the table() function you may alter columns using the ->change() method at the end of your call. Basically what you need is to specify all the characteristics of your columns as if it were a new one but just call change() at the end of the chain. Like this: $table->string('mail')->after('other_example_column')->nullable()->change()

But be careful - if the new data type does not match the old one, you might loose data. In addition, there is a module that needed to be included to laravel in order to modify columns, but it was a long time ago when I last had to enable that functionality so I forgot the details... but there was something exceptional!

Hope that narrows it down for you.

1 like
daniel21gt's avatar

Suppose I make the change in the migration, but I do not understand how to execute that migration, without deleting the data that I already have in the users table

Sergiu17's avatar
Sergiu17
Best Answer
Level 60

create new migration

php artisan make:migration remove_unique_key --table=users
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropUnique('users_email_unique');
        });
    }
php artisan migrate
daniel21gt's avatar

Thank you very much, I do not erase data, now I understand

Please or to participate in this conversation.