Laravel: ошибка миграции при наличии индекса - PullRequest
0 голосов
/ 09 января 2020

Я получаю следующую ошибку при запуске миграции. Ошибка в моей терминальной консоли:

SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'referral_code' used in key specification without a key length (SQL: alter table `users` add index `users_referral_code_index`(`referral_code`))

Ниже приведен мой фактический файл миграции. Я не могу понять, почему это происходит, так как я использовал этот шаблон ранее с другими миграциями.

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddReferralInfoToUsersTable extends Migration
{
    public function up()
    {
        Schema::table('shop_users', function (Blueprint $table) {
            $table->text('referral_code')->nullable();
            $table->integer('referral_uses')->nullable();
            $table->integer('referral_revenue')->nullable();
            $table->index(['referral_code']);
        });
    }
}

Ответы [ 2 ]

0 голосов
/ 09 января 2020

Вы можете попробовать это:

Schema::table('shop_users', function (Blueprint $table) {
            $table->mediumText('referral_code')->nullable();
}

или

Schema::table('shop_users', function (Blueprint $table) {
            $table->string('referral_code',100)->nullable();
}

или

 Schema::table('shop_users', function (Blueprint $table) {
            $table->longText('referral_code')->nullable();
}
0 голосов
/ 09 января 2020

Попробуйте изменить тип данных referral_code на строку и установить длину.

Schema::table('shop_users', function (Blueprint $table) {
        $table->string('referral_code',100)->nullable();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...