laravel migrate:rollback wrong
laravel, laravel-5, mysql, php
Solution
Your index is dropped automatically when you drop your column. So then when you try to drop the index separately, you get the error that it doesn't exist.
So either swap the order, and drop the index first:
$table->dropIndex('user_id');
$table->dropColumn('user_id');
Or just drop the column, and don't worry about the index.
From the MySQL manual:
If columns are dropped from a table, the columns are also removed from any index of which they are a part. If all columns that make up an index are dropped, the index is dropped as well.
Problem
Laravel version 5.1.43(LTS) I use `php artisan migrate:rollback` in terminal then return error messages. But the database is changed. Then I re-entered this command again there is no error messages. Can anybody help me fix this problem? [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP'user_id'; check that column/key exists (SQL: alter table `crm_user` drop index `user_id`) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'user_id'; check that column/key exists My migration code ``` public function down() { if (Schema::hasColumn('crm_user', 'user_id')) { Schema::table('crm_user', function (Blueprint $table) { $table->dropColumn('user_id'); $table->dropIndex('user_id'); }); } } ```