【发布时间】:2018-10-08 17:11:39
【问题描述】:
用户代码
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->integer('role_id')->unsigned();
$table->foreign('role_id')->references('id')->on('user_role')->onDelete('cascade');
$table->rememberToken();
$table->timestamps();
});
}
用户角色代码
public function up()
{
Schema::create('user_roles', function (Blueprint $table) {
$table->increments('id');
$table->string('user_role');
$table->timestamps();
});
}
SQLSTATE[HY000]: 一般错误: 1005 Can't create table sms.#sql-1718_62 (errno: 150 "外键约束格式不正确") (SQL: alter table users add constraint users_role_id_foreign外键(role_id)在删除级联时引用user_role(id)
【问题讨论】:
-
甚至添加 $table->integer('role_id')->unsigned();也有错误。我可以知道是什么问题吗?