Kev*_*lds 5 php mysql laravel laravel-migrations
我正在尝试创建char 数据类型的可为空外键。当我运行迁移命令时。我收到以下错误。我不确定我哪里做错了。
[Illuminate\Database\QueryException] SQLSTATE[HY000]:一般错误:1215 无法添加外键约束(SQL:alter table
levels
添加约束levels_sample_type_id_foreign
外键 (sample_type_id
) 引用sample_types
(id
))[PDOException] SQLSTATE[HY000]:一般错误:1215 无法添加外键约束
这是级别表的迁移文件内容
public function up()
{
Schema::create('levels', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->char('id', 36)->unique();
$table->string('description')->nullable();
$table->char('sample_type_id', 36)->nullable();
$table->integer('order');
$table->timestamps();
$table->primary('id');
$table->foreign('sample_type_id')->references('id')->on('sample_types');
});
}
Run Code Online (Sandbox Code Playgroud)
对于sample_types表如下
public function up()
{
Schema::create('sample_types', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->char('id', 36)->unique();
$table->string('name');
$table->timestamps();
$table->primary('id');
});
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1237 次 |
最近记录: |