我正在尝试在两个表之间创建一个fk。这是我的迁移:
public function up()
{
Schema::create('contracts', function (Blueprint $table) {
$table->increments('id');
// Some other cols removed for this post
$table->string('user_file_path');
$table->timestamps();
$table->foreign('user_file_path')->references('path')->on('user_files');
});
}
和
public function up()
{
Schema::create('user_files', function (Blueprint $table) {
$table->increments('id');
$table->integer('application_id')->unsigned();
$table->string('random', 32);
$table->string('path');
$table->timestamps();
$table->foreign('application_id')->references('id')->on('applications');
});
}
运行php artisan migrate
General error: 1005 Can't create table 'dashboard'.'#sql-1890_b6' (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table 'contracts' add constraint 'contracts_user_file_path_foreign' foreign key ('user_file_path') references 'user_files' ('path'))
我在做什么错了?
答案 0 :(得分:1)
您为什么不引用user_files
的{{1}}记录,例如
id