1

I have create a table stack_links as below

Schema::create('stack_links', function (Blueprint $table) {
            $table->increments('id');
            $table->string('site_key');
            $table->string('url');
            $table->string('path_run')->nullable();
            $table->integer('state');
            $table->integer('parent')->nullable();
            $table->text('data');
            $table->timestamps();

            $table->unique(['site_key', 'url']);

            $table->index(['site_key']);
            $table->index(['state']);
            $table->index(['parent']);
            $table->index(['url']);
        });

Now i want to change url column to text type. So i have tried this

 $table->text('url')->change();

Hower it return this err

1170 BLOB/TEXT column 'url' used in key specification without a key length

After searching, i found that the err because url is indexed(MySQL error: key specification without a key length). So i remove index but it still the same err. i follow : https://laravel.com/docs/5.5/migrations#dropping-indexes

Schema::table('stack_links', function (Blueprint $table) {
            $table->dropUnique(['url']);
            $table->dropIndex(['url']);

            $table->text('url')->change();
            $table->string('md5_url');

            $table->unique('md5_url');
            $table->index('md5_url');
        });

Can anyone tell me where am i wrong.

Update : The problem is the parameter of dropIndex. When i replace it with the name of index. It work

7
  • stackoverflow.com/questions/1827063/… follow this i think this will help you. Commented Jan 9, 2018 at 4:53
  • @KuldeepMishra i have removed index, but it still log the same err Commented Jan 9, 2018 at 4:56
  • laravel.com/docs/5.5/migrations have you checked this link ?? Commented Jan 9, 2018 at 5:05
  • Man, using unique on that url is going to be super costly for you in the future if you start dealing with tons of records. Now, regarding your problem, you absolutely must use a length on a text column when you want it to be an index. so... $table->text('url', 1024)->change() for instance. Commented Jan 9, 2018 at 5:10
  • @KuldeepMishra just write out what i should correct , please don't write the link, because i have read it, but maybe i have not understand enough Commented Jan 9, 2018 at 5:14

1 Answer 1

1

Try DB Statement -

 public function up()
{
    DB::statement('ALTER TABLE stack_links DROP INDEX stack_links_url_index');
    DB::statement('ALTER TABLE stack_links MODIFY COLUMN url TEXT');
}
public function down()
{
    DB::statement('ALTER TABLE stack_links CREATE INDEX stack_links_url_index');
    DB::statement('ALTER TABLE stack_links MODIFY COLUMN url STRING');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.