0

When i create Laravel5 migration as follows it adds "linkdesc" column as a primary key. when i read the documentation of laravel5 migration it does not mentioned that $table->text('description'); this gives a primary key in database. is there any way to prevent such automatically added primary keys in laravel5 ? Also is there any other migration functionalities that give this kind of unwanted primary keys ?

my migration is as follows

Schema::create('articles', function (Blueprint $table) {

        $table->primary(['pemail', 'linkid']);
        $table->bigInteger('linkid');
        $table->string('pemail');
        $table->string('linkname');
        $table->string('linkurl');
        $table->integer('linorder');
        $table->text('linkdesc')->nullable();


    });
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
kasunb
  • 157
  • 1
  • 9
  • Why are you removing the standard `id` primary key? – Martin Bean Jul 24 '15 at 17:53
  • I've run this migration and everything is as expected. There is a composite primary key on pemail and linkid, no key on linkdesc. – jedrzej.kurylo Jul 24 '15 at 18:06
  • @Martin Bean : i have normalized all of my database tables. so i get rid of all unnecessary columns – kasunb Jul 24 '15 at 18:08
  • @ jedrzej.kurylo : nope.. it still give the problem. please refer this screenshot http://mywebengineer.com/other/stckoverflowImages/lv-migration.jpg – kasunb Jul 24 '15 at 18:15

1 Answers1

1

I think you misread the info you get in PhpMyAdmin. You have primary word inactive without possibility to click on it in the row for linkdesc column and you thought Laravel creates primary key for this column.

However the truth is quite different - it's inactive not because Laravel created automatically primary key for this field but because it's a text field and texts fields cannot be primary keys.

You can verify it when you click in PhpMyAdmin on Indexes - it should be below the table - there you will see there is no primary key on linkdesc column.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291