vendredi 11 novembre 2016

how to alter an existing table column in laravel 5.3 using migrations

I have this:

$table->integer('role_id')->index()->unsigned()->nullable();

But I want to change it to this:

$table->integer('role_id')->index()->unsigned()->nullable()->default(3);

I had wanted to use this, but the source syntax I could not understand:

php artisan make:migration update_role_id_in_users --table=users

I even tried using doctrine/ddbal package and running this:

php artisan make:migration modify_role_id_in_users --table=users

But I get this error:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'users_role_id_index' (SQL: alter table 'users' add index 'users_role_id_index'('role_
id'))

[Doctrine\DBAL\Driver\PDOException] SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'users_role_id_index'

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'users_role_id_index'

How can I alter the column without doing a migrate:refresh



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire