You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can not create a unique index on a column of an existing table.
I have two migrations files.
The first one is the 2016_08_29_135919_create_users_table.php file:
<?phpuseIlluminate\Database\Schema\Blueprint;
useIlluminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/** * Run the migrations. * * @return void */publicfunctionup()
{
Schema::create('users', function (Blueprint$table) {
$table->increments('id');
$table->string('email');
$table->timestamps();
});
}
/** * Reverse the migrations. * * @return void */publicfunctiondown()
{
Schema::drop('users');
}
}
The second is the 2016_08_29_140747_add_index_to_users_table_email_column.php file:
<?phpuseIlluminate\Database\Schema\Blueprint;
useIlluminate\Database\Migrations\Migration;
class AddIndexToUsersTableEmailColumn extends Migration
{
/** * Run the migrations. * * @return void */publicfunctionup()
{
Schema::table('users', function (Blueprint$table) {
$table->unique('email');
});
}
/** * Reverse the migrations. * * @return void */publicfunctiondown()
{
Schema::table('users', function (Blueprint$table) {
$table->dropUnique('users_email_unique');
});
}
}
When I using SchemaExtended\Schema and executing the Artisan migrate command, the following error occur:
$ php artisan migrate
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near ')' at line 1 (SQL: alter table `users` add unique users_email_unique())
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near ')' at line 1
The second migration seem is not applied.
mysql> desc users;
+------------+------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | | NULL | |
| created_at | timestamp | NO | | 0000-00-00 00:00:00 | |
| updated_at | timestamp | NO | | 0000-00-00 00:00:00 | |
+------------+------------------+------+-----+---------------------+----------------+
4 rows in set (0.00 sec)
When I using Illuminate\Support\Facades\Schema and executing the Artisan migrate command, the error does not occur:
I can not create a unique index on a column of an existing table.
I have two migrations files.
The first one is the
2016_08_29_135919_create_users_table.php
file:The second is the
2016_08_29_140747_add_index_to_users_table_email_column.php
file:When I using
SchemaExtended\Schema
and executing the Artisanmigrate
command, the following error occur:The second migration seem is not applied.
When I using
Illuminate\Support\Facades\Schema
and executing the Artisanmigrate
command, the error does not occur:Two of the migration has been applied:
The text was updated successfully, but these errors were encountered: