1

I have tried this code and run the migrations that ships with sentry 2 by doing this: php artisan migrate:--package cartalyst/sentry. I was able to create the user, group, and other tables in my database.

How do i change the ID column of the user table from being the PRIMARY KEY to userID which i added as a migration?

Gustavo Straube
  • 3,744
  • 6
  • 39
  • 62
Chritech
  • 33
  • 7
  • generate a fresh migration that adds userID to the users table , then set primary on the column, that should fix your issue. – osleonard Mar 04 '15 at 10:37
  • But it already has 'id' as a primary key, so it tells me that i cant have two primary keys, and whats the effect setting another primary key will have on the referential integrity? – Chritech Mar 04 '15 at 11:51
  • are you want a rename column 'id' to 'userID' on sentry users table ? – Jay Dhameliya Mar 05 '15 at 10:20

1 Answers1

0

Try it

Generate new fresh migration using php artisan migrate:make and write below code

public function up() {
    Schema::table('users', function(Blueprint $table) {
        $table->dropPrimary('users_id_primary');
        $table->integer("userID");
        $table->primary('userID');
    });
}

public function down() {
    Schema::table('users', function(Blueprint $table) {
        $table->dropPrimary('userID');
        $table->dropColumn('userID');
        $table->primary('users_id_primary');

    });
}

Then after run php artisan migrate

Next and change you User Model

use Cartalyst\Sentry\Users\Eloquent\User as SentryUserModel;

class User extends SentryUserModel {

    protected $primaryKey = 'userID';
}

Next

php artisan config:publish cartalyst/sentry

Next open the config file in app/config/packages/cartalyst/sentry and edit

'users' => array(
 'model' => 'User',
 ...
 ),

Hope it will be helpful :)

Jay Dhameliya
  • 1,689
  • 12
  • 25
  • Will this affect anything in the referencing? cos i think somehow, sentry must have tied the primary key which is 'id' with something somewhere or so. I just want to be sure that after changing the primary key to another column, it wont cause any problems.. – Chritech Mar 05 '15 at 07:43
  • will this change affect places in sentry code where 'id' has been used to query the database? – Chritech Mar 05 '15 at 10:02