I would do this to make my email field unique
in the table.
$table->unique('email');
I've tried
public function up() { Schema::table('contacts', function(Blueprint $table) { $table->dropUnique('email'); }); }
Then, when I run php artisan migrate, I got this
It tell me that it's not there, but I'm 100% sure that it's there.
How do write a migration to undo that ?
The part with migrate:rollback is the actual command. It says that you want to rollback certain database migrations. The last part, --step=1 , is a parameter for the migrate:rollback command. By default, php artisan migrate:rollback will rollback all of your database migrations.
The syntax for dropping a unique constraint in MySQL is: ALTER TABLE table_name DROP INDEX constraint_name; table_name.
IF you want to re-migrate all the database, you can simply do: php artisan migrate:refresh . IF you want to make sure your database to be clean with your latest changes, you can drop your entire database tables and do php artisan migrate again. Also, you can try php artisan migrate --seed if you have any seeder.
When you run artisan migrate then it will only run migrations that haven't already been applied unless you use migrate:refresh in which case it will reset and re-run all migrations.
You have to do $table->dropUnique('users_email_unique');
To drop an index you must specify the index's name. Laravel assigns a reasonable name to the indexes by default. Simply concatenate the table name, the names of the column in the index, and the index type.
This the better way to drop unique. You can use the real column name here.
$table->dropUnique(['email']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With