In laravel 5.8 app I created migration file with 1 field and 1 index added
class SubscriptionsTableAddIsFreeField extends Migration
{
public function up()
{
Schema::table('subscriptions', function (Blueprint $table) {
$table->boolean('is_free')->default(false)->after('source_service_subscription_id');
$table->index([ 'user_id', 'is_free' ], 'subscriptions_user_id_is_free_index');
});
}
public function down()
{
Schema::table('subscriptions', function (Blueprint $table) {
$table->dropForeign('subscriptions_user_id_is_free_index');
$table->dropColumn('is_free');
});
}
But running command
php artisan migrate:refresh --seed
I got error :
: SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'subscriptions_user_id_is_free_index'; check that column/key exists (SQL: alter table `vt2_subscriptions` drop foreign key `subscriptions_user_id_is_free_index`)
at /mnt/_work_sdb8/wwwroot/lar/votes/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'subscriptions_user_id_is_free_index'; check that column/key exists")
/mnt/_work_sdb8/wwwroot/lar/votes/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:119
2 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'subscriptions_user_id_is_free_index'; check that column/key exists")
/mnt/_work_sdb8/wwwroot/lar/votes/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117
Please use the argument -v to see more details.
What is wrong in defintion of my migration?
I know that laravel migration has methods
if (Schema::hasTable('users')) {
//
}
if (Schema::hasColumn('users', 'email')) {
//
}
But can I check indexes?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire