I have started writing a small personal project on Laravel 10. The problem I encountered is as follows:
public function up(): void { Schema::table('users', function (Blueprint $table) { $table->foreignUuid('role_id')->nullable()->constrained('roles')->change(); }); } /*** Reverse the migrations.*/ public function down(): void { Schema::table('users', function (Blueprint $table) { $table->foreignUuid('role_id')->nullable(false)->constrained('roles')->change(); }); }
But when I run php artisan migrate, I get the following error - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'role_id' (Connection: mysql, SQL: alter table users add role_id char(36 ) null).
Any suggestions on how to modify the columns correctly would be greatly appreciated.
You can try the following:
Or you can use the original SQL statement: