2
你好,我有麻煩我的數據庫遷移這是錯誤:Laravel 1215不能在我的laravel應用</p> <p>添加外鍵約束
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
: alter table `transactions` add constraint `transactions_user_sid_foreign`
foreign key (`user_sid`) references `users` (`sid`))
這是我的交易遷移:
public function up()
{
Schema::create('transactions', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_sid')->index();
$table->unsignedInteger('store_id')->index();
$table->unsignedInteger('value');
$table->timestamps();
$table->softDeletes();
});
}
這是用戶遷移:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->unsignedInteger('role_id')->index();
$table->string('sid')->unique();
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
}
最後我的外鍵:
Schema::table('transactions', function (Blueprint $table){
$table->foreign('user_sid')->references('sid')->on('users');
$table->foreign('store_id')->references('id')->on('stores');
});
什麼遷移序列? –