【发布时间】:2019-07-10 10:54:18
【问题描述】:
我有一个“posts”表和一个“arrival”表,其中引用了“flightno”(以文本字符串格式)作为外键。但是,当我运行 Laravel 迁移时,我得到了可怕的错误:
[照亮\数据库\查询异常] SQLSTATE[HY000]: 一般错误: 1005 Can't create table
atc.#sql-2350_84(errno: 150 "外键约束是 格式不正确”) (SQL: alter tablearrivaladd constraintarrival_flightno_foreign外键 (flightno) 引用posts(flightno))[PDO异常] SQLSTATE[HY000]: 一般错误: 1005 Can't create table
atc.#sql-2350_84(errno: 150 "外键约束是 格式不正确")
帖子
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('flightno');
$table->string('flighttype');
$table->string('toa');
$table->string('doa');
$table->string('runway');
$table->string('route');
$table->string('parking');
$table->timestamps();
});
到达
Schema::create('arrival', function (Blueprint $table) {
$table->increments('id');
$table->string('flightno');
$table->string('cleaning');
$table->string('rampservice');
$table->string('waste');
$table->string('deicing');
$table->foreign('flightno')->references('flightno')->on('posts')->onDelete('cascade');
$table->timestamps();
});
【问题讨论】:
标签: laravel laravel-5 laravel-5.4