I have make username and email unique in migration but it is allowing same email and username entry in database.
$table->string('userName')->unique();
$table->string('email')->unique();
Here is the screenshot of the table:
Database table
My Answer:
It looks like you have set the 'userName' and 'email' columns to be unique in your migration file, which should prevent duplicate entries in the database.
If you are still able to insert duplicate values into these columns, it could be due to a few reasons:
1. Make sure you have run the migration file after making the changes. If you haven't run the migration, the unique constraint won't be applied to the database table.
2. Check if there are any existing duplicate values in the 'userName' and 'email' columns before adding the unique constraint. If there are duplicates already present, you will need to remove them before the unique constraint can be enforced.
3. Verify that there are no other constraints or triggers in the database that could be overriding the unique constraint you have set in the migration file.
If you have checked all of the above and are still facing issues, you may need to provide more information or code for further assistance.
Rate this post
4 of 5 based on 2984 votesComments