更改哨兵2用户迁移表的主键


change primary key of sentry 2 user migration table

我已经尝试过这段代码,并通过执行以下操作来运行哨兵2附带的迁移:php artisan migrate:--package cartalyst/sentry. 我能够在数据库中创建用户、组和其他表。

如何将用户表的ID列从PRIMARY KEY更改为作为迁移添加的userID

试试

使用php artisan migrate:make生成新的新迁移,并在下面编写代码

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');
    });
}

然后运行php artisan migrate

下一步并更改您的User型号

use Cartalyst'Sentry'Users'Eloquent'User as SentryUserModel;
class User extends SentryUserModel {
    protected $primaryKey = 'userID';
}

下一步

php artisan config:publish cartalyst/sentry

接下来打开app/config/packages/cartalyst/sentry中的配置文件并编辑

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

希望它会有所帮助:)