繁体   English   中英

更改哨兵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生成新的新php artisan migrate:make和write下面的代码

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',
 ...
 ),

希望它会有所帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM