[英]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.